feathers-plus / generator-feathers-plus

A Yeoman generator to (re)generate a FeathersJS application supporting both REST and GraphQL architectural concepts and their query languages.
https://generator.feathers-plus.com/
Other
44 stars 30 forks source link

Schema must be an instance of GraphQLSchema #247

Closed IceOnFire closed 4 years ago

IceOnFire commented 5 years ago

Steps to reproduce

(First please check that this issue is not already solved as described here)

After generating the graphql service, exploring it through GraphiQL generates an error.

Steps:

  1. Create a service
  2. Create the graphql service
  3. Run server
  4. Navigate to http://localhost:3030/graphql with GraphiQL

Expected behavior

The GraphQL service should just run smoothly.

Actual behavior

Tell us what happens instead

This is the error I see in console:

error: BadRequest: Schema must be an instance of GraphQLSchema. Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory.
    at new BadRequest (/home/antony/Progetti/EpiCura/epicura-backend/node_modules/@feathers-plus/graphql/node_modules/@feathersjs/errors/lib/index.js:81:17)
    at graphql.catch.err (/home/antony/Progetti/EpiCura/epicura-backend/node_modules/@feathers-plus/graphql/lib/index.js:79:17)
    at process._tickCallback (internal/process/next_tick.js:68:7)

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that's not working):

  "@feathers-plus/graphql": "^1.10.0",
  "@feathersjs/feathers": "^3.3.1",
  "graphql-resolvers-ast": "^1.4.0",
  "merge-graphql-schemas": "^1.5.8",

  "@types/graphql": "^0.13.4",

NodeJS version:

v10.15.2

Operating System:

Ubuntu 18.10

Browser Version:

GraphiQL

React Native Version:

No React Native

Module Loader:

No Module Loader

eddyystop commented 5 years ago

Please post your feathers-gen-specs.json and the module serviceName.schema.?s.

You need to define schema and extensions as per the docs if you want GraphQL to function. See https://generator.feathers-plus.com/get-started/#graphql and https://generator.feathers-plus.com/get-started/#graphql-extensions-to-models

IceOnFire commented 5 years ago

Sure thing. feathers-gen-specs.json:

{
  "options": {
    "ver": "1.0.0",
    "inspectConflicts": false,
    "semicolons": false,
    "freeze": [],
    "ts": true
  },
  "app": {
    "environmentsAllowingSeedData": "",
    "seedData": false,
    "name": "epicura-backend",
    "description": "Back end server for EpiCura.",
    "src": "src",
    "packager": "npm@>= 3.0.0",
    "providers": [
      "rest",
      "socketio"
    ]
  },
  "services": {
    "users": {
      "name": "users",
      "nameSingular": "user",
      "subFolder": "",
      "fileName": "users",
      "adapter": "mongodb",
      "path": "/users",
      "isAuthEntity": true,
      "requiresAuth": true,
      "graphql": true
    },
    "roles": {
      "name": "roles",
      "nameSingular": "role",
      "subFolder": "",
      "fileName": "roles",
      "adapter": "mongodb",
      "path": "/roles",
      "isAuthEntity": false,
      "requiresAuth": true,
      "graphql": true
    }
  },
  "hooks": {},
  "authentication": {
    "strategies": [
      "local",
      "auth0"
    ],
    "entity": "users"
  },
  "connections": {
    "mongodb": {
      "database": "mongodb",
      "adapter": "mongodb",
      "connectionString": "mongodb://localhost:27017/epicura"
    }
  },
  "graphql": {
    "path": "/graphql",
    "strategy": "services",
    "sqlInterface": null,
    "requiresAuth": false,
    "doNotConfigure": false,
    "name": "graphql"
  }
}

serviceName.schema.?s:


// Define the Feathers schema for service `users`. (Can be re-generated.)
// !code: imports // !end
// !code: init // !end

// Define the model using JSON-schema
let schema = {
  // !<DEFAULT> code: schema_header
  title: 'Users',
  description: 'Users database.',
  // !end
  // !code: schema_definitions // !end

  // Required fields.
  required: [
    // !code: schema_required
    'email',
    'password',
    // !end
  ],
  // Fields with unique values.
  uniqueItemProperties: [
    // !code: schema_unique // !end
  ],

  // Fields in the model.
  properties: {
    // !code: schema_properties
    _id: { type: 'ID' },
    email: {},
    firstName: {},
    lastName: {},
    password: {},
    roleId: { type: 'ID' },
    // !end
  },
  // !code: schema_more // !end
}

// Define optional, non-JSON-schema extensions.
let extensions = {
  // GraphQL generation.
  graphql: {
    // !code: graphql_header
    name: 'User',
    service: {
      sort: { _id: 1 },
    },
    // sql: {
    //   sqlTable: 'Users',
    //   uniqueKey: '_id',
    //   sqlColumn: {
    //     __authorId__: '__author_id__',
    //   },
    // },
    // !end
    discard: [
      // !code: graphql_discard
      'password',
      // !end
    ],
    add: {
      // !code: graphql_add
      // __author__: { type: '__User__!', args: false, relation: { ourTable: '__authorId__', otherTable: '_id' } },
      fullName: { type: 'String!', args: false },
      role: {
        type: 'Role',
        args: true,
        relation: { ourTable: 'roleId', otherTable: '_id' },
      },
      // !end
    },
    // !code: graphql_more // !end
  },
}

// !code: more // !end

let moduleExports = {
  schema,
  extensions,
  // !code: moduleExports // !end
}

// !code: exports // !end
export default moduleExports

// !code: funcs // !end
// !code: end // !end

I followed both guides and created both services with the generator.

eddyystop commented 5 years ago

I need roles.schema.?s also to recreate your situation.

IceOnFire commented 5 years ago

Nothing unusual I think:

// Define the Feathers schema for service `roles`. (Can be re-generated.)
// !code: imports // !end
// !code: init // !end

// Define the model using JSON-schema
let schema = {
  // !<DEFAULT> code: schema_header
  title: 'Roles',
  description: 'Roles database.',
  // !end
  // !code: schema_definitions // !end

  // Required fields.
  required: [
    // !code: schema_required
    'name',
    // !end
  ],
  // Fields with unique values.
  uniqueItemProperties: [
    // !code: schema_unique // !end
  ],

  // Fields in the model.
  properties: {
    // !code: schema_properties
    _id: { type: 'ID' },
    name: {},
    // !end
  },
  // !code: schema_more // !end
}

// Define optional, non-JSON-schema extensions.
let extensions = {
  // GraphQL generation.
  graphql: {
    // !code: graphql_header
    name: 'Role',
    service: {
      sort: { _id: 1 },
    },
    // sql: {
    //   sqlTable: 'Roles',
    //   uniqueKey: '_id',
    //   sqlColumn: {
    //     __authorId__: '__author_id__',
    //   },
    // },
    // !end
    discard: [
      // !code: graphql_discard // !end
    ],
    add: {
      // !code: graphql_add
      // __author__: { type: '__User__!', args: false, relation: { ourTable: '__authorId__', otherTable: '_id' } },
      users: {
        type: '[User!]',
        args: false,
        relation: { ourTable: '_id', otherTable: 'roleId' },
      },
      // !end
    },
    // !code: graphql_more // !end
  },
}

// !code: more // !end

let moduleExports = {
  schema,
  extensions,
  // !code: moduleExports // !end
}

// !code: exports // !end
export default moduleExports

// !code: funcs // !end
// !code: end // !end
eddyystop commented 5 years ago

Its more a matter of my regenerating the core of your app.

lunchboxer commented 5 years ago

I can recreate this from scratch:

mkdir feathers-app
cd feathers-app
feathers-plus generate options
feathers-plus generate app
feathers-plus generate authentication

then I add something in the user schema like username and password. Everything else is just sticking with the defaults.

feathers-plus generate service
feathers-plus generate graphql
npm start

Then open up graphiql and voila, badschema error:

error: BadRequest: Schema must be an instance of GraphQLSchema. Also ensure that there are not multiple versions of GraphQL installed in your node_modules directory.

You can see this repo for details

bencyu commented 5 years ago

I believe the error was due to the conflict of the graphql packages. I ran the following commands and the error was gone.

npm install graphql@^0.11.7
npm dedupe
iva2k commented 5 years ago

Yes, this fixes the issue:

npm install graphql@^0.11.7
npm dedupe

However, the problem seems to be self-inflicted by feathers-plus packages.

Here's a "requires" in package-lock.json from feathers-hooks-common that installs graphql@14.2.0 or later (I got 14.3.1 in my node_modules)

    "feathers-hooks-common": {
      "version": "4.20.7",
      "resolved": "https://registry.npmjs.org/feathers-hooks-common/-/feathers-hooks-common-4.20.7.tgz",
      "integrity": "sha512-+9CXrj2FeDAOlDmU7MBdmYg72F+na17kss/97Vyus4zRbLJvuV2ky6Jto16NSJ906OsbYjHHXKIKzw1uPnlx3w==",
      "requires": {
        "@feathers-plus/batch-loader": "0.3.6",
        "@feathersjs/commons": "1.4.4",
        "@feathersjs/errors": "3.3.6",
        "@feathersjs/feathers": "3.3.1",
        "@types/graphql": "14.2.0",
        "ajv": "5.5.2",
        "debug": "3.2.6",
        "graphql": "14.3.1",
        "libphonenumber-js": "1.7.18",
        "process": "0.11.10",
        "traverse": "0.6.6"
      },

Is there a way to prune/coordinate the dependencies so that the versions mish-mash won't happen when the guide is followed? And how is that v0.11.7 in one package and v14.3.1 in another suppose to work together in the first place?

Heartnett commented 5 years ago

I'm experiencing the same issue, but the install and dedupe commands did not work for me.