Graphql-tools: `extend type` requires non-empty type to extend when calling makeExecutableSchema

Created on 18 Dec 2016  ·  4Comments  ·  Source: ardatan/graphql-tools

I'm using extend type Query to put my queries into separate files and it works great with the following code:

const schema = `
  scalar GraphQLDate

  # Queries that the schema supports
  type Query {
    dummy: [String]
  }  
`;

export default makeExecutableSchema({
    typeDefs: [
        schema,
        donations.schema,
        projects.schema,
        partners.schema,
        donors.schema
    ],
    resolvers
})

An example of how I'm extending the Query type is from my donors.js file here:

export const schema = `
  # A person who has donated money to one or more projects
  type Donor {
    id: Int!
    user_id: Int
    name: String!
    slug: String!
    donated_sum: Float
    image: String
    donations: [Donation]
  }

  extend type Query {
    # Donors who have given money to projects
    donors: [Donor]
  }
`

It works great but requires the dummy query.

if I remove the type Query in the variable schema I get the error 'Must provide schema definition with query type or a type named Query.'.

If I change the schema variable to have an empty type Query {} I get the error Error: Query fields must be an object with field names as keys or a function which returns such an object.

So I'm left with having to provide a dummy query that serves no purpose, shows up in GraphiQL and doesn't work if it is called.

Most helpful comment

I'm having the same issue. I want to extend the Query (Or rootQuery) type.

How do you resolve that issue?

All 4 comments

@proehlen yes, this is a limitation that @tmeasday has also run into. It's imposed by graphql-js, so there's not much we can do about it.

@helfer OK, thanks for the feedback.

I'm having the same issue. I want to extend the Query (Or rootQuery) type.

How do you resolve that issue?

Oh...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

flippidippi picture flippidippi  ·  3Comments

ericclemmons picture ericclemmons  ·  4Comments

dcworldwide picture dcworldwide  ·  4Comments

Adherentman picture Adherentman  ·  4Comments

freiksenet picture freiksenet  ·  4Comments