ExamplesGraphQL

GraphQL Mocking

Learn how to mock GraphQL APIs with MockMaster.

For complete examples with detailed code, see the GraphQL Mocking section in MASTER_DOCUMENTATION.md.


GraphQL Query

const getUserQuery = `
  query GetUser($id: ID!) {
    user(id: $id) {
      id
      name
      email
    }
  }
`
 
const recording = createRecording(
  {
    method: 'POST',
    path: '/graphql',
    body: {
      query: getUserQuery,
      variables: { id: '1' }
    },
    timestamp: Date.now()
  },
  {
    status: 200,
    body: {
      data: {
        user: {
          id: '1',
          name: 'John Doe',
          email: 'john@example.com'
        }
      }
    },
    timestamp: Date.now()
  }
)

Full Documentation

See MASTER_DOCUMENTATION.md for complete GraphQL examples.