Graphql-yoga: Unable to start server with mocks

Created on 22 May 2018  Â·  5Comments  Â·  Source: dotansimha/graphql-yoga

I am trying to start yoga server with mocks.
Just copy-pasting example from the docs doesn't work:

import { GraphQLServer, MockList } from 'graphql-yoga'

const typeDefs = `
  type Query {
    hello(name: String): String!
    listOfStrings: [String]
  }
`

const mocks = {
  Query: () => ({
    hello: () => 'Hello World',
    listOfStrings: () => new MockList([2, 6]),
  }),
}

const server = new GraphQLServer({ typeDefs, mocks })
server.start()

And got an Error: No schema defined, at /node_modules/graphql-yoga/src/index.ts

statupr-welcome

Most helpful comment

@checkmatez @merelinguist I dont know if there is bug or feature, but you have to pass at least empty resolvers.

import { GraphQLServer, MockList } from 'graphql-yoga'

const typeDefs = `
  type Query {
    hello(name: String): String!
    listOfStrings: [String]
  }
`

const mocks = {
  Query: () => ({
    hello: () => 'Hello World',
    listOfStrings: () => new MockList([2, 6]),
  }),
}

const server = new GraphQLServer({ typeDefs, resolvers: () => true, mocks })
server.start()

All 5 comments

I had the same issue, when following the mocking example in the README.

@checkmatez @merelinguist I dont know if there is bug or feature, but you have to pass at least empty resolvers.

import { GraphQLServer, MockList } from 'graphql-yoga'

const typeDefs = `
  type Query {
    hello(name: String): String!
    listOfStrings: [String]
  }
`

const mocks = {
  Query: () => ({
    hello: () => 'Hello World',
    listOfStrings: () => new MockList([2, 6]),
  }),
}

const server = new GraphQLServer({ typeDefs, resolvers: () => true, mocks })
server.start()

@borisowsky Thanks! That works perfectly. ✨

Due to inactivity of this issue we have marked it stale. It will be closed if no further activity occurs.

Hey :wave:, It seems like this issue has been inactive for some time. In need for maintaining clear overview of the issues concerning the latest version of graphql-yoga we'll close it.
Feel free to reopen it at any time if you believe we should futher discuss its content. :slightly_smiling_face:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yesprasad picture yesprasad  Â·  3Comments

kv-pawar picture kv-pawar  Â·  3Comments

ahmedosama5200 picture ahmedosama5200  Â·  4Comments

bellomusodiq picture bellomusodiq  Â·  3Comments

woss picture woss  Â·  5Comments