Modify multi query arguments in graphQL-JS

Modify multi query arguments in graphQL-JS


0

I am building an app using graphQL, neo4j and Apollo client and running into issue with multi-query. I want to implicitly apply argument to multi-query on server side when user pass payload without arg. For example:

query {
  books(where: { cust_id: "1"}) { name }
  posts { description }
  cars { type }
}

In the above query, it seems the graphQL server will return all the records for posts and cars. However, the behavior I want is for posts and cars to apply same filter as books; i.e., in our example it would be cust_id:1.

I have tried using AST parse but I am not sure how to set argument object.

const originalDocument = parse(body)
const operationDefinition = originalDocument.definitions[0]
const selections = operationDefinition.selectionSet.selections
// not sure how to set argument for selections coz arguments object is complex and not regular json object (in-terms of keys and value)

arguments in selectionSet:

Modify multi query arguments in graphQL-JS

Any guidance is appreciated.

Note: user of my service can do following:

query {
  books(where: { cust_id: "1"}) { 
  name 
  posts { description }
  cars { type }
  }
}

and it would work as expected but there are instance where user won’t do it or when they want data which are not related.

Using: neo4j/graphql: 2.0.0, apollo-server: 2.19, apollo-client: 3.2.5


Load 4 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *