Introducing GraphQL Paper
GraphQL Paper is a flexible in-memory store based on a provided GraphQL Schema.
In testing and development it is handy to have a store that reflects the current state of the world, handles connections between data, and updates via mutations. While GraphQL Paper integrates well with the rest of graphql-mocks, it can also be used on its own.
✨ Features
- Built and based on GraphQL
- Works in the Browser and Node JS
- Works without
graphql-mockswith support for the official default GraphQL resolvers - Written in TypeScript
- Support and integration with
graphql-mocks - Support for relationships and connections between types
- Support for serialization and deserialization
- Immutable
- Accessible via native js APIs
- Hooks (docs)
- Events (docs)
- Transaction Operations (docs)
- Validations (docs)
- API Query Imports
Coming Soon:
- Time-travel debugging, store snapshots, and the ability to restore to existing store snapshots
- Specialized
factoryoperation with support for various states and scenarios, with functional factories currently working now (docs)
API Reference
There is the API reference available for the graphql-paper package.
Integration with graphql-mocks
Check out the guide for using graphql-mocks with GraphQL Paper.
Documents and the Store
With GraphQL Paper a Document is a POJO (plain-old javascript object) that represents a concrete GraphQL type, it is not an instance.
For example an Actor GraphQL type:
type Actor {
title: String!
}
Could have a corresponding Document:
{
title: 'Jurassic Park'
}
Documents are stored in an array on the DocumentStore keyed by the GraphQL type. Based on the previous example a basic store containing our document could look like:
{
Actor: [{ title: 'Jurassic Park' }]
}
This is a simplistic, but realistic example, of how data is stored. Learn how to query and mutate the store (see below for a quick example of both). Check out the technical notes for a closer look at how everything works.
A Quick Example
Here's a quick glimpse at what is possible with GraphQL Paper:
[object Promise]```
First console.log for title
"West Side Story"
Second console.log for actors
[
{
"name": "Rita Moreno"
},
{
"name": "Natalie Wood"
},
{
"name": "George Chakiris"
},
{
"name": "Richard Beymer"
}
]
Third console.log for richard
{
"name": "Richard Beymer"
}