0

In GraphQL, is it possible to fetch data with a 'filtered' array (e.g. only with a single object) instead of an array with all the (multiple) objects? For instance, by providing the 'id' property for the selected object you want to get in the query.

If yes, what needs to be changed in the below query? Just wondering if this filtering can already be done server side.


const selectedId = 'n32j23h'

const query = gql`
  query getData {
    dataObj {
      bigArray {
        id
        name
      }
    }
  }
`;

1 Answer 1

1
  1. Define a new query in your typeDefs:
query getDataById(id: ID!): returnObjectType
  1. Implement a resolver for that query that uses the id parameter to filter your bigArray
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.