Skip to content

couldn't add schema extension plugin #8

Open

Description

@yleigh

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");

const SchemaExtensionPlugin = 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
...

Is this supported here?

Activity

  1. benjie commented on Jul 28, 2020

    @benjie
    Member

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

  2. yleigh commented on Jul 28, 2020

    @yleigh
    Author

    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?

  3. benjie commented on Jul 28, 2020

    @benjie
    Member

    Is there a way that this could work with federatedSchema from apollo-server?

    No idea.

  4. yleigh commented on Jul 28, 2020

    @yleigh
    Author

    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?

  5. benjie commented on Jul 29, 2020

    @benjie
    Member

    Looks like your versions are out of date.

  6. yleigh commented on Jul 29, 2020

    @yleigh
    Author

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

  7. yleigh commented on Jul 29, 2020

    @yleigh
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions