anyone have good strategies for dealing with Graph...
# graphql
j
anyone have good strategies for dealing with GraphQL aliases in queries when introspecting the
DataFetchingEnvironment.selectionSet
? Just ran into https://github.com/graphql-java/graphql-java/issues/1545 and can workaround some cases of it relatively easily, but others less so. We look at the qualifiedName of the leaf fields of the selectionSet to dynamically decide how to build our underlying query. When that leaf field is aliased, we can use
SelectedField.name
to go back to the schema name and build the right query to run, but if a parent field is aliased, there doesn't seem to be a way to access the schema-qualified name, only the aliased one?
for example, a query:
Copy code
query {
    visits {
       all
       us
       uk
    }
}
we can map the
qualifiedName
of
visits/us
to our desired underlying query pretty easily. if a user aliases
visits{america:us}
we can chop
america
off of
visits/america
and append
us
from the field's name. but if a user does something like:
usVisits: visits { us }
it's not straightforward how to deal with that alias? (example here is a little contrived, but I think illustrates the problem?)
Seems like the best way to handle this is to navigate the field selectionSet field tree directly and look at each field's
name
to build the path from the root node down, avoiding any of the glob methods or qualifiedName properties. That's working for us, but would love to know if there are any other approaches.