Apollo-server: extend type Query keyword doesn't work

Created on 11 Jun 2018  路  6Comments  路  Source: apollographql/apollo-server

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.

Most helpful comment

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.

All 6 comments

@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?

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

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

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.

@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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

veeramarni picture veeramarni  路  3Comments

deathg0d picture deathg0d  路  3Comments

dupski picture dupski  路  3Comments

disyam picture disyam  路  3Comments

dbrrt picture dbrrt  路  3Comments