# GraphQL

A service mock can configure a GraphQL endpoint using the graphql option:

const myService = {
  graphql: {
    typeDefs: '...', // the GraphQL schema
    mocks: {},
    resolvers: {},
    fixtures: {}
  }
}

To provide a GraphQL endpoint, a service simply needs to provide a GraphQL schema using graphql.typeDefs or graphql.typeDefsPath:

const myService = {
  graphql: {
    typeDefs: `
      type Book {
        id: Int
        title: String
      }
      type Query {
        books: [Book]
      }
    `
  }
}

If your package is an ES module:

const myService = {
  graphql: {
    typeDefsPath: new URL('./my-schema.graphql', import.meta.url)
  }
}

If your package is not an ES module:

const myService = {
  graphql: {
    typeDefsPath: path.resolve(__dirname, './my-schema.graphql')
  }
}

This will ensure the full schema is auto-mocked.

To further customize responses, see the available mocking levels.

# Importing an existing schema

When mocking an existing schema, we can use the CLI to download the schema.