question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Override GraphQLArgument object type to provide more details to clients

See original GitHub issue

I’m probably doing this completely wrong, but I have a simple GraphQLQuery where the method signature is essentially

@GraphQLQuery(name = url)
public List<Entity> searchAll(@GraphQLArgument(name="filter") Entity filter) {
return search(filter)
}

That wraps up a matcher search so that some of our clients that want a general purpose search can pass an id into the filter or another attribute and get back a filtered list. The problem becomes that in an attempt to extend this to be able to take nulls, the method signature has to move to being a Map so that we can distinguish when a value is null because it wasn’t set, or null because the client want to search on null (such as figuring out which customers don’t have a telephone number set). So my first issue I ran into is that you can’t have a Map<String, Object> as the GraphQLArgument as I get an error saying

[
"Validation error of type WrongType: argument value ObjectValue{objectFields=[ObjectField{name='id', value=IntValue{value=1}}]} has wrong type"
]

where it doesn’t like converting from an Int to an Object . That’s not the best, but I can set the argument to be an object and then cast it to a map so that it can still be searched like so:

@GraphQLQuery(name = url)
public List<Entity> searchAll(@GraphQLArgument(name = "filter", ) Object filter) {
Map<String, Object> where = ((LinkedHashMap) filter);
return search(where)
}

My issue then becomes GraphiQL which loses information about the argument and can only refer to it as “ObjectScalar”. Is there a way to override how it is reported back to GraphiQL, such as setting a type in the argument so that it can be mapped to the relevant entity in GraphiQL allowing clients to know that the argument should really be in the layout of the Entity?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

0reactions
kaqqaocommented, Dec 5, 2017

I don’t mind extending the discussion. Better clear it up than have you confused 😃

Unless there’s a setter for subEntities exposed (i.e. setSubEntities), or you configure your Jackson to use reflection (I think there’s such a setting) or have a @JsonCreator constructor, the default InputFieldDiscoveryStrategy will ignore that field when mapping EntityInput. Since InputFieldDiscoveryStrategy only delegates to Jackson, it’s better to reconfigure Jackson than mess with the strategy itself.

As a general rule, I wholeheartedly recommend exposing service classes that work with DTOs, instead of DAO/repository classes working with domain objects/persistent entities directly, so yeah, that’s probably a good idea in your case too in any case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reusable GraphQL schema directives
Today we're excited to introduce a convenient yet powerful tool for implementing custom directive syntax: the SchemaDirectiveVisitor class. To ...
Read more >
graphql-java/GraphQLArgument.java at master - GitHub
* classes have been introduced to better model when a directive is applied to a schema element,. * as opposed to its schema...
Read more >
Arguments - GraphQL Ruby
Default Values. Another approach is to use default_value: value to provide a default value for the argument if it is not supplied in...
Read more >
Queries and Mutations - GraphQL
On this page, you'll learn in detail about how to query a GraphQL server. Fields#. At its simplest, GraphQL is about asking for...
Read more >
GraphQL API style guide - GitLab Docs
For details see GraphQL Pro subscription. ... Breaking change exemptions ... This provides the clients with a lot of flexibility while also allowing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found