Skip to content

Mockstore how to work with collections? #2673

Answered by alexstrat
sporto asked this question in Q&A
Discussion options

You must be logged in to vote

If, in your schema, a given field returns a list of object type (or abstract type), then, in the MockStore, the corresponding field value will be an array of Refs, ie references to entities in the store. Therefore, working with lists means working with this array of Refs: get, set, push, filter, pop etc..

The default mock resolvers will interpret these Refs properly, and deep resolve the fields values.

With your example:

For the sake of clarity, I'm assuming we are working with such schema:

type User {
  id: ID!
  name: String!
}
type Query {
  users: [User!]!
}

Accessing, the value in the store for the query users:

store.get('Query', 'ROOT',  'users')
> [{ $ref: { key: 'abc-737dh-djdjd', t…

Replies: 5 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@sporto
Comment options

Answer selected by ardatan
Comment options

You must be logged in to vote
1 reply
@alexstrat
Comment options

You must be logged in to vote
1 reply
@Urigo
Comment options

Urigo Feb 28, 2022
Collaborator

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants