Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend type Query keyword doesn't work #1158

Closed
mortenko opened this issue Jun 11, 2018 · 6 comments
Closed

extend type Query keyword doesn't work #1158

mortenko opened this issue Jun 11, 2018 · 6 comments

Comments

@mortenko
Copy link

mortenko commented Jun 11, 2018

extend keyword doesn't work in schema

I'm modularizing my graphql schemas and I would like to extend Query in schema Product but I still get following error: Error: Query.products defined in resolvers, but not in schema.
This is just shortened form of my code.

Resolvers for Customer and Product schemas have following structure:

const [schema_name]resolvers = {
Query: {
.....
products: () => {.....}
},
Mutation: {
products: () => {.....}
......
}
}

Customer schema:

const Customer = `
 type Customer {
  customerID: ID!
  firstname: String
  lastname: String
  phone: String
  email: String
  CustomerPhoto: CustomerPhoto
 } 
 input CustomerInput {
  firstname: String!
  lastname: String!
  phone: String!
  email: String!
  } 
 type Query {
  customers(cursor: Int!): [Customer]
  customer(id: Int!): Customer
 }
`;

Product schema

const Product = ` 
 type Product {
  productID: ID!
  name: String!
  description: String!
  pricewithoutdph: Float!
  pricewithdph: Float!
  barcode: Int!
  ProductPhoto: ProductPhoto
 }
  extend type Query {
   products: [Product]
   product(productID: ID!): Product
  }
`;

Here Im importing schemas using export default .

const SchemaDefinition = `
 schema {
  query: Query
  mutation: Mutation
 }`;

const schema = makeExecutableSchema({
  typeDefs: [SchemaDefinition,Customer, Product],
  resolvers: merge(ProductResolvers,CustomerResolvers),
  logger: {
    log: e => {
      console.log(e);
    }
  },
  resolverValidationOptions: {
    requireResolversForNonScalar: true
  }
});

It works only if I have just only one query. The same problem is with mutations.

Thanks for help.

@mortenko mortenko changed the title extend keyword doesn't work extend type Query keyword doesn't work Jun 11, 2018
@evans
Copy link
Contributor

evans commented Jun 13, 2018

@mortenko Can you make a reproduction of the issue, similar to https://glitch.com/edit/#!/vigorous-bone?path=server.js:1:0?

Is this with Apollo Server 2 or 1?

@mortenko
Copy link
Author

Hi evans.
thanks for answer. Im using apollo server for express.js

@evans
Copy link
Contributor

evans commented Jun 18, 2018

If you run npm install apollo-server@rc, does it work with the extend keyword?

@ErinCall
Copy link

I'm not using apollo (I found this issue while searching the error), but I think this is the situation described in graphql/graphql-js#922. It looks like version 0.12.0 has a breaking change to how extend type is handled and it requires a corresponding update to graphql-tools.

Pinning graphql to 0.11.7 fixed the problem for me, as did upgrading graphql-tools to 3.0.2.

@mortenko
Copy link
Author

@ErinCall thanks for answer. I have version of graphql 0.13.0 and I did upgrade of graphql-tools to 3.0.2. (before I had v2.13.0) . Now it finally works!

Thanks for help guys @evans @ErinCall

@evans
Copy link
Contributor

evans commented Jun 22, 2018

Great to hear! I'm going to close this now

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants