You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This source code works fine if I just changed the connection string to my Postgres db.
However, I would like to use Apollo federation with this. Trying to add my own schema extension plugin, like:
const{ makeExtendSchemaPlugin, gql }=require("graphile-utils");constSchemaExtensionPlugin=makeExtendSchemaPlugin(build=>{// Get any helpers we need from `build`const{pgSql: sql, inflection }=build;return{typeDefs: gql` type NewType @key(fields: "id") { id: Int! name: String stuff: ExistingType } extend type ExistingType @key(fields: "upc") { upc: String! @external } `,resolvers: { ... }};});module.exports=SchemaExtensionPlugin;
But got error like:
node_modules\graphile-utils\node8plus\makePgSmartTagsPlugin.js:9
[graphile_build_pg_1.PgEntityKind.CLASS]: "for tables, composite
types, views and materialized views",
^
TypeError: Cannot read property 'CLASS' of undefined
at Object.<anonymous> (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\node_modules\graphile-utils\node8plus\makePgSmartTagsPlugin.js:9:39)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\node_modules\graphile-utils\node8plus\index.js:24:22)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
...
My first guess would be that it's a version mis-match; e.g. an older postgraphile with a new graphile-utils, or maybe duplicate modules. Could you eliminate these first by updating the modules and then running npx yarn-deduplicate && yarn (assuming you're using yarn; if you're using npm then the process may be more manual).
Thanks. Yes, that works. End up with package.json: { "dependencies": { "@apollo/federation": "^0.18.0", "@graphile/federation": "0.0.3", "apollo-server": "latest", "graphile-utils": "^4.7.0", "graphql": "^14.2.1", "pg": "7.11.0", "postgraphile": "4.4.0", "postgraphile-apollo-server": "0.1.1", "graphile-build": "^4.5.0", "graphile-build-pg": "^4.5.0" } }
But then the GraphQL playground has message:
This GraphQL server either doesn't support Apollo Federation, or the query plan extensions is disabled. See the docs for setting up query plan viewing with Apollo Federation.
Then I added following to schemaExtensionPlugin typeDefs, using a type 'Product' from an outside GraphQL service: extend type Product @key(fields: "upc") { upc: String! @external }
Error: Could not find type named 'Product'.
In server.js, tried adding const schema = buildFederatedSchema(dbSchema);
and modifying current to: const server = new ApolloServer({ schema, plugins: [plugin], });
Got error:
`node_modules@apollo\f
ederation\dist\service\buildFederatedSchema.js:31
if ('typeDefs' in modulesOrSDL) {
^
TypeError: Cannot use 'in' operator to search for 'typeDefs' in public
at buildFederatedSchema (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-
server\node_modules@apollo\federation\dist\service\buildFederatedSchema.js:31:
20)
at Object. (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-se
rver\server.js:26:16)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.j
s:71:12)
at internal/main/run_main_module.js:17:47
error Command failed with exit code 1.`
Is there a way that this could work with federatedSchema from apollo-server?
As Apollo server complaining, added @graphile/federation, but error is probably some other incompatibility.
Added in server.js: const { default: FederationPlugin } = require("@graphile/federation"); const postGraphileOptions = { appendPlugins: [FederationPlugin, schemaExtensionPlugin],
Error message: $ node server.js Error: Sorry, 'GraphQLUnionType:types' is not a supported hook at SchemaBuilder.hook (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\node_modules\pos tgraphile-core\node_modules\graphile-build\node8plus\SchemaBuilder.js:130:13) at AddKeyPlugin (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\node_modules\@graphile \federation\build\index.js:153:13) at C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\node_modules\graphile-utils\node8plu s\makePluginByCombiningPlugins.js:6:19 at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Object.exports.getBuilder (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\nod e_modules\postgraphile-core\node_modules\graphile-build\node8plus\index.js:110:5) at async exports.createPostGraphileSchema (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-ser ver\node_modules\postgraphile-core\node8plus\index.js:214:21) at async exports.makeSchemaAndPlugin (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\n ode_modules\postgraphile-apollo-server\index.js:130:18) at async main (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\server.js:26:30) error Command failed with exit code 1.
But if I tried to add apollo server buildFederateSchema like: const federatedSchema = buildFederatedSchema(schema);
Got error: TypeError: Cannot read property 'kind' of undefined at KnownDirectives (C:\Workspace\emcp-gql-federation\nodejs\ pg-apollo-server\node_modules\graphql\validation\rules\KnownDire ctives.js:48:13) at C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\ node_modules\graphql\validation\validate.js:91:12 at Array.map (<anonymous>) at Object.validateSDL (C:\Workspace\emcp-gql-federation\node js\pg-apollo-server\node_modules\graphql\validation\validate.js: 90:24) at Object.buildSchemaFromSDL (C:\Workspace\emcp-gql-federati on\nodejs\pg-apollo-server\node_modules\apollo-graphql\lib\schem a\buildSchemaFromSDL.js:43:31) at buildFederatedSchema (C:\Workspace\emcp-gql-federation\no dejs\pg-apollo-server\node_modules\@apollo\federation\dist\servi ce\buildFederatedSchema.js:45:35) at main (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-s erver\server.js:42:27) at processTicksAndRejections (internal/process/task_queues.j s:97:5)
checking out the lib internally, _ast's document.definitions is an array with only null in it, causing problem.
Seems like the schema here is missing some properties.
Activity
benjie commentedon Jul 28, 2020
My first guess would be that it's a version mis-match; e.g. an older postgraphile with a new graphile-utils, or maybe duplicate modules. Could you eliminate these first by updating the modules and then running
npx yarn-deduplicate && yarn(assuming you're usingyarn; if you're using npm then the process may be more manual).yleigh commentedon Jul 28, 2020
Thanks. Yes, that works. End up with package.json:
{ "dependencies": { "@apollo/federation": "^0.18.0", "@graphile/federation": "0.0.3", "apollo-server": "latest", "graphile-utils": "^4.7.0", "graphql": "^14.2.1", "pg": "7.11.0", "postgraphile": "4.4.0", "postgraphile-apollo-server": "0.1.1", "graphile-build": "^4.5.0", "graphile-build-pg": "^4.5.0" } }But then the GraphQL playground has message:
This GraphQL server either doesn't support Apollo Federation, or the query plan extensions is disabled. See the docs for setting up query plan viewing with Apollo Federation.
Then I added following to schemaExtensionPlugin typeDefs, using a type 'Product' from an outside GraphQL service:
extend type Product @key(fields: "upc") { upc: String! @external }Error: Could not find type named 'Product'.
In server.js, tried adding
const schema = buildFederatedSchema(dbSchema);and modifying current to:
const server = new ApolloServer({ schema, plugins: [plugin], });Got error:
`node_modules@apollo\f
ederation\dist\service\buildFederatedSchema.js:31
if ('typeDefs' in modulesOrSDL) {
^
TypeError: Cannot use 'in' operator to search for 'typeDefs' in public
at buildFederatedSchema (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-
server\node_modules@apollo\federation\dist\service\buildFederatedSchema.js:31:
20)
at Object. (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-se
rver\server.js:26:16)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.j
s:71:12)
at internal/main/run_main_module.js:17:47
error Command failed with exit code 1.`
Is there a way that this could work with federatedSchema from apollo-server?
benjie commentedon Jul 28, 2020
No idea.
yleigh commentedon Jul 28, 2020
As Apollo server complaining, added @graphile/federation, but error is probably some other incompatibility.
Added in server.js:
const { default: FederationPlugin } = require("@graphile/federation"); const postGraphileOptions = { appendPlugins: [FederationPlugin, schemaExtensionPlugin],Error message:
$ node server.js Error: Sorry, 'GraphQLUnionType:types' is not a supported hook at SchemaBuilder.hook (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\node_modules\pos tgraphile-core\node_modules\graphile-build\node8plus\SchemaBuilder.js:130:13) at AddKeyPlugin (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\node_modules\@graphile \federation\build\index.js:153:13) at C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\node_modules\graphile-utils\node8plu s\makePluginByCombiningPlugins.js:6:19 at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Object.exports.getBuilder (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\nod e_modules\postgraphile-core\node_modules\graphile-build\node8plus\index.js:110:5) at async exports.createPostGraphileSchema (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-ser ver\node_modules\postgraphile-core\node8plus\index.js:214:21) at async exports.makeSchemaAndPlugin (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\n ode_modules\postgraphile-apollo-server\index.js:130:18) at async main (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\server.js:26:30) error Command failed with exit code 1.Any suggestions to move this ahead?
benjie commentedon Jul 29, 2020
Looks like your versions are out of date.
yleigh commentedon Jul 29, 2020
updated package json to follows, and working:
{ "dependencies": { "@apollo/federation": "^0.18.0", "@graphile/federation": "0.0.3", "apollo-server": "^2.16.1", "graphile-build": "^4.7.0", "graphile-build-pg": "^4.7.0", "graphile-utils": "^4.7.0", "graphql": "^14.7.0", "pg": "7.11.0", "postgraphile": "^4.7.0", "postgraphile-apollo-server": "0.1.1" } }yleigh commentedon Jul 29, 2020
But if I tried to add apollo server buildFederateSchema like:
const federatedSchema = buildFederatedSchema(schema);Got error:
TypeError: Cannot read property 'kind' of undefined at KnownDirectives (C:\Workspace\emcp-gql-federation\nodejs\ pg-apollo-server\node_modules\graphql\validation\rules\KnownDire ctives.js:48:13) at C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-server\ node_modules\graphql\validation\validate.js:91:12 at Array.map (<anonymous>) at Object.validateSDL (C:\Workspace\emcp-gql-federation\node js\pg-apollo-server\node_modules\graphql\validation\validate.js: 90:24) at Object.buildSchemaFromSDL (C:\Workspace\emcp-gql-federati on\nodejs\pg-apollo-server\node_modules\apollo-graphql\lib\schem a\buildSchemaFromSDL.js:43:31) at buildFederatedSchema (C:\Workspace\emcp-gql-federation\no dejs\pg-apollo-server\node_modules\@apollo\federation\dist\servi ce\buildFederatedSchema.js:45:35) at main (C:\Workspace\emcp-gql-federation\nodejs\pg-apollo-s erver\server.js:42:27) at processTicksAndRejections (internal/process/task_queues.j s:97:5)checking out the lib internally, _ast's document.definitions is an array with only null in it, causing problem.
Seems like the schema here is missing some properties.