Field policies and arrays

(this is a continuation of a previous post.

I have field policies working fine for queries that return a single type; what I can’t figure out is how to handle arrays of a type being returned.

type Query {
  getOpeningForFen2(fen: String!) : Opening2     
  getSimilarOpenings(fen: String!): [SimilarOpening] 
}

The first query I can create a policy for Opening2 fields that fetch data from local storage.

The second query is returning an array of that SImilarOpening. While I can pull locally stored data for fields for each instance of SimilarOpening, the query still goes out to the remote server for the array (of which only the size is used).

Request:

Response:

Note that there is no data in the response, because the fields have a policy defined to fetch locally stored data.

I hope that is sufficiently clear.

I’ve concluded that field policies are working at a level too low for what I am trying to do. A mock server may be the answer, but I have a question about that as well.

It seems like it should be easy to implement: “given query payload X, return local data value Y”. So far I’m not finding it.

Hi @Jeff_Lowery :wave:

given query payload X, return local data value Y

This is possible using readQuery and/or readFragment. See:

You might also consider using Cache Redirects:

If neither of these address your use case, let me know! Happy to help you figure out the right abstraction.

Thanks again, Jeff. The first option would probably work, and perhaps the second, but it’s a bit more configuration-heavy than I hoped for.

For now I’m just going to rate limit non-credentialed clients, which should be easier to manage. I appreciate the education, though. :slight_smile:

1 Like