Skip to main content

Quick Example

This example will show how to:

  1. Create a Resolver Map with Resolver functions
  2. Apply a Resolver Wrapper to Resolver functions, the Sinon Spy Wrapper spyWrapper (via @graphql-mocks/sinon) by using embed. The spy wrapper will capture all calls to our resolver function which can be useful for testing.
  3. Setup a GraphQL Handler with the the Resolver Wrapper to be able to execute queries
  4. Execute a Query with the GraphQL Handler
  5. Check the state object for the results of the Sinon Spies
[object Promise]```

First console.log

Result:
{
  "data": {
    "helloWorld": "Hello from our test resolver!"
  }
}

Second console.log

Result:
"Hello from our test resolver!"

And that's an end-to-end example using the library to create a quick mock GraphQL API with the Sinon Spy Wrapper for introspection. Use the existing out-of-the-box Resolver Wrapper and Resolver Map Middlewares for even more functionality, or create your own.