0
votes

I am using apollo-cache-inmemory, apollo-client, react-apollo.

My local state contains a users array like so: -

users: [{

__typename: "User",

userId: "hashid1",

...
},

{

__typename: "User",

userId: "hashid2",

...
}]

Now I can obviously run a simple query to retrieve all the users from the local state: -

import gql from "graphql-tag"
export default gql`{users @client {userId}}`

However, what I would like to do is to be able to query the users array directly, passing variables like so: -

const userDetails = await client.query({ query: USER_DETAILS, variables: {id: "hashId1"}})

Is it possible to run this query without using a resolver? I have attempted the following but { data } returns as null: -

export default gql`query user($id: String!) {users(userId: $id) @client {userId}}`

I already use resolvers and can easily write one to take care of this issue but I am wondering if there it is possible to perform this task without one?

1

1 Answers

1
votes

It looks like you're looking for some magic ;)

You must write customization code (overwrite default resolver - return all records) to have a customized behavior (return data filtered by your criteria). That should be obviuos.

There is no default/ready/built in searching/filtering syntax in graphql - therefore, there is no default behaviours for them in apollo-client (no matter local/remote server/data). It is up to you to implement what you need.