1

I'm working on migrating an GraphQL app from using Postgraphql 3.10 with a Postgresql version 9.6 database to using postgraphile version 4.7.0 and a Postgresql version 11 database.

The graphql query below used to work in the old version but fail in the new version.

query supplier($id: Int!) {
    supplierById(id: $id) {
        id accountId
        title intro description
        imageBg imageProfile imageProfileRot
        rating status
        productsBySupplierId(condition: {published: true, deleted: false}) { 
            nodes { 
                id type prodTitle prodDescr 
                price currency duration { hours minutes }
            } 
        }
        reviewsBySupplierId(condition: {target: SUPPLIER}) {
            nodes {comment rating createdAt}
        }
    }
}

The failure is because of the condition filter and the error message say:

"GraphQLError: Field \"published\" is not defined by type ProductCondition."
"GraphQLError: Field \"deleted\" is not defined by type ProductCondition."
"GraphQLError: Field \"target\" is not defined by type ReviewCondition."

I can't find any documentation about how to set up the database table to support this condition. Do I need to add the fields published, deleted and target to some index for postgraphile to support this condition?

Postgraphile config in express app

app.use( postgraphile( `postgres://${account}:${passwd}@localhost:5432/${database}`, schema, {
        pgDefaultRole: '*****_anonymous',
        dynamicJson: true,
        jwtSecret: Buffer.from( secret, 'hex' ).toString(),
        jwtPgTypeIdentifier: '*****.jwt_token',
        enableCors: true,
        disableQueryLog: false,
        graphiql: config.web.graphiql,
        graphqlRoute: config.web.graphql,
        graphiqlRoute: '/qtest',
        subscriptions: true,
        watchPg: true,
        setofFunctionsContainNulls: false,
        ignoreRBAC: false,
        ignoreIndexes: false,
        showErrorStack: "json",
        extendedErrors: ['severity', 'code', 'detail', 'hint', 'position', 'internalPosition', 'internalQuery', 'where', 'schema', 'table', 'column', 'dataType', 'constraint', 'file', 'line', 'routine'],
        //extendedErrors: ["hint", "detail", "errcode"],
        //appendPlugins: [require("@graphile-contrib/pg-simplify-inflector")],
        exportGqlSchemaPath: "schema.graphql",
        sortExport: true,
        enhanceGraphiql: true,
        allowExplain(req) {
                // TODO: customise condition!
                return true;
        },
        enableQueryBatching: true,
        disableDefaultMutations:false,
        legacyRelations: "omit"
} ) )
ola
  • 129
  • 1
  • 10
  • For v3 compat, try using the default settings rather than the recommended settings; in particular remove the ignore indexes setting override. If this doesn’t solve it, share your config. Also note we have a v3 v4 migration guide on the website. – Benjie Jun 29 '20 at 23:43
  • @Benjie I added the config – ola Jun 30 '20 at 15:16
  • I commented out the "ignoreIndexes: false" setting and then the ProductCondition and the ReviewCondition suddenly contain all fields and the query don't fail anymore – ola Jun 30 '20 at 15:53
  • Yes; ignore indexes removes fields from conditions/order if they don't have indexes (because they could potentially be expensive to do) – Benjie Jul 02 '20 at 16:05

0 Answers0