Skip to content

graphql.language.Field usage #4022

Answered by bbakerman
momentary-lapse asked this question in Q&A
Discussion options

You must be logged in to vote

graphql.language.Field as its name suggests is the AST representation of graphql query text. And yes it can be parsed into a string with some tricks

The parser does NOT start from a syntax element of field but its can be tricked

    static Field parseField(String sdlField) {
        String spec = """ query Foo {
        $sdlField
        }
        """
        def document = parseQuery(spec)
        def op = document.getDefinitionsOfType(OperationDefinition.class)[0]
        return op.getSelectionSet().getSelectionsOfType(Field.class)[0] as Field
    }

parseField("f(arg : 1) { inner sub selection }") for example

The thing is Field and graphql.language.SelectionSet is not really a represen…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@momentary-lapse
Comment options

Answer selected by momentary-lapse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants