Dynamic gql queries without arguments, possible?
See original GitHub issueIs it possible to construct gql string variables with passed variables as such?:
getRules(model: string){
var queryVar = gql`
query HyperionSchemaQuery {
rules {
`+model+` {
rules
}
}
}
`;
var rulesArray;
this.apollo.watchQuery({
query: queryVar
}).subscribe(({data}) => {
rulesArray = JSON.parse(data.rules[model].rules);
console.log(rulesArray);
});
}
this.getRules(“Day”); gives error:
EXCEPTION: Error in ./ProjectMain class ProjectMain - inline template:191:108 caused by: Syntax Error GraphQL (4:7) Expected Name, found EOF
3: rules {
4:
^
A multiline string variable, without the “gql” logs the following:
var queryVar = `
query HyperionSchemaQuery {
rules {
`+model+` {
rules
}
}
}
`;
logs:
query HyperionSchemaQuery {
rules {
Day {
rules
}
}
}
Which would be how an accepted graphql-query would look like in my case. Is there some way I could construct such a variable and pass it as the query in my watchQuery()? Iv’e tested in many different ways (to construct the gql`` string) without success and can’t find anything in the documentation or in the GitHunt example.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
GraphQL query best practices
If two otherwise identical queries have different hardcoded argument values, they're considered entirely different operations by your GraphQL server's cache.
Read more >Compose queries dynamically — gql 3 3.5.0b0 documentation
Arguments ¶. It is possible to add arguments to any field simply by calling it with the required arguments: ds.
Read more >GraphQL dynamic query building - apollo - Stack Overflow
Most GraphQL tutorials seem to focus on static queries (e.g. where the only thing that is changing is the variables, but not the...
Read more >Queries and Mutations - GraphQL
This is also in general a good practice for denoting which arguments in our query are expected to be dynamic - we should...
Read more >Understanding Queries in GraphQL - DigitalOcean
Arguments serve the same purpose as your traditional query parameters or URL segments in a REST API. We can pass them into our...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
this should work
@patriknil90 I just want to warn you that this is not a good way of using GraphQL, see here: https://dev-blog.apollodata.com/5-benefits-of-static-graphql-queries-b7fa90b0b69a