0

我正在将 GraphQL 应用程序从使用 Postgraphql 3.10 和 Postgresql 9.6 版数据库迁移到使用 postgraphile 4.7.0 版和 Postgresql 11 版数据库。

下面的 graphql 查询曾经在旧版本中工作,但在新版本中失败。

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}
        }
    }
}

失败是因为条件过滤器和错误消息说:

"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."

我找不到任何关于如何设置数据库表来支持这种情况的文档。我是否需要将已发布、删除和定位的字段添加到 postgraphile 的某个索引以支持此条件?

Express 应用程序中的 Postgraphile 配置

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"
} ) )
4

0 回答 0