Git Product home page Git Product logo

Comments (19)

benjie avatar benjie commented on June 16, 2024

We've not released this to npm yet (it's still at the proof-of-concept stage); if you want to try it out copy these files into your project and require index.js directly:

https://github.com/graphile/pg-aggregates/tree/master/src

What aggregates are you looking for? You may also wish to track graphile/graphile-engine#465

from pg-aggregates.

Murthy10 avatar Murthy10 commented on June 16, 2024

Thank you for the tip, I will have a look at graphile-engine and follow the updates of this repo.

from pg-aggregates.

benjie avatar benjie commented on June 16, 2024

@Murthy10 The aggregates are added directly to the connection, your query tries to query it on the nodes. If you use a tool like GraphiQL it should help you to construct your query with typeahead and linting.

Try:

{
  allPayments {
      aggregates{
        sum {
      		amount          
        }
      }
  }
}

from pg-aggregates.

enewhuis avatar enewhuis commented on June 16, 2024

Is there any way to get this to work with the CLI in the docker image?

from pg-aggregates.

benjie avatar benjie commented on June 16, 2024

There's no instructions on how to do that as it's not officially released yet. You'd do it the same way - add the files to the docker image and then tell PostGraphile where to find them.

from pg-aggregates.

BrunoMovio avatar BrunoMovio commented on June 16, 2024

I'm having some issue when added files from https://github.com/graphile/pg-aggregates/tree/master/src and required index.td directly.
How I`m doing:

import  AggregatePlugin from "./_common/graphql/plugins/pg-aggregates"
...

const buildServer = async () => {
  const connection = await connectionPromise
  const pgPool = (connection?.driver as any).master
  const { schema: graphileSchema, plugin } = await makeSchemaAndPlugin(
    pgPool,
    schemas, // PostgreSQL schema to use
    {
      dynamicJson: true,
      appendPlugins: [ConnectionFilterPlugin],
      graphiql: true,
      enhanceGraphiql: true,
      watchPg: true,
      jwtSecret: getConfig().PasswordHash,
      // jwtPgTypeIdentifier: 'public.jwt_token',
      pgDefaultRole: 'postgres',
      allowExplain: true
    }
  )
  return new ApolloServer({
    schema: mergeSchemas({
      schemas: [graphileSchema, schema],
    }),
    plugins: [queryComplexityPlugin, AggregatePlugin, plugin],
    context: async ({ event, context: lambdaContext }) => {
      const requestId = lambdaContext.awsRequestId
      const container = Container.of(requestId)

      await connectionPromise

      const authorizerContent = event.requestContext?.authorizer
      const graphQLContext: Partial<OSContext> = {
        uid: authorizerContent?.uid,
        userRole: authorizerContent?.userRole,
        requestId,
        container,
      }
      return graphQLContext
    },
...

I'm sewing two schemas and giving priority to the one generated by the postgraphile. However, when trying to generate the schema I'm taking:

TypeError: Cannot read property 'hook' of undefined

That 'hook' should be a property of 'build' on AddAggregatesPlugin. @benjie would you help me? Am I forgetting to set up something?

from pg-aggregates.

benjie avatar benjie commented on June 16, 2024

Try updating all your graphile-related software, it's possible your dependencies are out of date and don't support this yet.

from pg-aggregates.

benjie avatar benjie commented on June 16, 2024

This is now an official released plugin; usage instructions are in the README 👍

from pg-aggregates.

apu-mdo avatar apu-mdo commented on June 16, 2024

@benjie I am getting error in graphiql -

query{
  allBrands(orderBy: PRICE_DESC){
    aggregates{
      sum{
        price
      }
    }
  }
  allSales(orderBy: QUANTITY_DESC, first: 2){
    totalCount
    nodes{
      quantity
      brandByBrandId{
        brandname
        price
        productByProductId{
          productname
        }
      }
      storeByStoreId{
        storename
      }
    }
    aggregates{
      sum{
        quantity
      }
    }
  }
}

Output

{
  "errors": [
    {
      "message": "Cannot read property '@aggregates' of undefined",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "allBrands",
        "aggregates"
      ]
    }
  ],
  "data": {
    "allBrands": {
      "aggregates": null
    },
    "allSales": {
      "totalCount": 11,
      "nodes": [
        {
          "quantity": 12,
          "brandByBrandId": {
            "brandname": "Brand E",
            "price": "500.50",
            "productByProductId": {
              "productname": "Product C"
            }
          },
          "storeByStoreId": {
            "storename": "Store C"
          }
        },
        {
          "quantity": 9,
          "brandByBrandId": {
            "brandname": "Brand C",
            "price": "300.50",
            "productByProductId": {
              "productname": "Product A"
            }
          },
          "storeByStoreId": {
            "storename": "Store B"
          }
        }
      ],
      "aggregates": {
        "sum": null
      }
    }
  }
}

from pg-aggregates.

benjie avatar benjie commented on June 16, 2024

Requires PostGraphile v4.12.0-alpha.0 or higher.

from pg-aggregates.

apu-mdo avatar apu-mdo commented on June 16, 2024

Yes, I am using -

"dependencies": {
"@graphile-contrib/pg-simplify-inflector": "^6.1.0",
"db-migrate": "^0.11.12",
"db-migrate-pg": "^1.2.2",
"postgraphile": "^4.12.0-alpha.0",
"@graphile/pg-aggregates": "^0.1.0"
}

from pg-aggregates.

benjie avatar benjie commented on June 16, 2024

Interesting; try npx yarn-deduplicate && yarn and then try again. If you're using npm try switching to yarn 😉

from pg-aggregates.

apu-mdo avatar apu-mdo commented on June 16, 2024

@benjie FYI, I dockerized a PostGraphile app by following steps in https://www.graphile.org/postgraphile/running-postgraphile-in-docker/

schema

package

graphql-Dockerfile

docker-compose-yaml

from pg-aggregates.

apu-mdo avatar apu-mdo commented on June 16, 2024

Output in graphiql -

Screen Shot 2021-04-23 at 8 45 04 AM

from pg-aggregates.

benjie avatar benjie commented on June 16, 2024

Please file an issue about these unexpected nulls, sending through the details (e.g. DB schema/data) as text that can be copied/pasted.

from pg-aggregates.

shubhamk244 avatar shubhamk244 commented on June 16, 2024

Hi @benjie ,
I face this issue "Cannot read property '@Aggregates' of undefined"
My dependencies are:
"@graphile/pg-aggregates": "^0.1.0",
"cluster": "^0.7.7",
"compression": "^1.7.4",
"consul": "^0.40.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"nodemon": "^2.0.4",
"pg": "^8.6.0",
"pm2": "^4.5.4",
"postgraphile": "^4.11.0",
"postgraphile-plugin-connection-filter": "^2.2.1",
"sequelize": "^6.6.2"

I changed the postgraphile version to "4.12.0". Also comes the same error.
Screenshot

from pg-aggregates.

benjie avatar benjie commented on June 16, 2024

Requires PostGraphile v4.12.0-alpha.0 or higher.
-- https://github.com/graphile/pg-aggregates#usage

I don't think you have a new enough version installed. Try yarn add postgraphile@next.

from pg-aggregates.

shubhamk244 avatar shubhamk244 commented on June 16, 2024

Thanks @benjie for the response.
I have solved the above problem.
I want to grouping "data_configuration" which has the same group a or b . I am attached db details for your reference
oie_HvklHT4PDz1x

And in my graphiql interface how i will group object. My graphiql interface is looks like
Screenshot (1)

from pg-aggregates.

benjie avatar benjie commented on June 16, 2024

You need to request subfields via a selection set on the grouped aggregates field.

from pg-aggregates.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.