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.

Directive locations causes null result

See original GitHub issue

Hi!

I have been trying to make graphql-javawork with Graphiql, I have noticed that at startup Graphiql sends the following query to the the GraphQL server:

query IntrospectionQuery {
    __schema {
      queryType { name }
      mutationType { name }
      types {
        ...FullType
      }
      directives {
        name
        description
        locations
        args {
          ...InputValue
        }
      }
    }
  }

  fragment FullType on __Type {
    kind
    name
    description
    fields(includeDeprecated: true) {
      name
      description
      args {
        ...InputValue
      }
      type {
        ...TypeRef
      }
      isDeprecated
      deprecationReason
    }
    inputFields {
      ...InputValue
    }
    interfaces {
      ...TypeRef
    }
    enumValues(includeDeprecated: true) {
      name
      description
      isDeprecated
      deprecationReason
    }
    possibleTypes {
      ...TypeRef
    }
  }

  fragment InputValue on __InputValue {
    name
    description
    type { ...TypeRef }
    defaultValue
  }

  fragment TypeRef on __Type {
    kind
    name
    ofType {
      kind
      name
      ofType {
        kind
        name
        ofType {
          kind
          name
          ofType {
            kind
            name
            ofType {
              kind
              name
              ofType {
                kind
                name
                ofType {
                  kind
                  name
                }
              }
            }
          }
        }
      }
    }
  }

When sending this query to graphql-java using the Hello World schema described in the README, the result ends up being null.

I have identified the field causing the error as the locations of directives. Here is a very simple program to reproduce the issue:

import graphql.GraphQL;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLSchema;

import java.util.Map;

import static graphql.Scalars.GraphQLString;
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
import static graphql.schema.GraphQLObjectType.newObject;

public class GraphQLTest {

    public static void main(String[] args) {

        GraphQLObjectType queryType = newObject()
                .name("helloWorldQuery")
                .field(newFieldDefinition()
                        .type(GraphQLString)
                        .name("hello")
                        .staticValue("world")
                        .build())
                .build();

        GraphQLSchema schema = GraphQLSchema.newSchema()
                .query(queryType)
                .build();
        String query = "{\n" +
                "    __schema {\n" +
                "      directives {\n" +
                "        locations\n" +
                "      }\n" +
                "    }\n" +
                "  }";
        Map<String, Object> result = (Map<String, Object>) new GraphQL(schema).execute(query).getData();

        System.out.println(result);
    }
}

The output I get from this is:

[main] INFO graphql.GraphQL - Executing request. operation name: null. Request: {
    __schema {
      directives {
        locations
      }
    }
  } 
null

Has anyone been able to make graphql-java work with graphiql?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dminkovskycommented, Aug 17, 2016

@IamCornholio #136 added the locations field but did not provide a data fetcher. I suppose that was enough for GraphiQL to work, but I don’t know how it would actually provide true results for that field without #175.

Closing this. Let’s continue on #175. Thanks everyone.

0reactions
ceronmancommented, Jul 30, 2016

I have tried this with the last version of graphql-java and graphiql worked just fine. It think this issue can be closed. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating schema directives - Apollo GraphQL Docs
The table below lists all available locations in a GraphQL schema. Your directive can support any combination of these locations.
Read more >
Directive on FIELD_DEFINITION returns whole object null #431
Expected Behaviour Directive on field makes whole object to null instead of the done field. The todo example in the repo. done: Boolean!...
Read more >
Does GraphQL Interpret null as truthy? - Stack Overflow
In GraphQL, I query all the pages for each component and its subfields. GraphQL returns the correct amount of components for each page,...
Read more >
Schema Directives – GraphQL Tools
Using and implementing custom directives to transform schema types, fields, and arguments.
Read more >
Directives - Hot Chocolate - ChilliCream GraphQL Platform
By default, directives are not repeatable, which means directives are unique and can only be applied once at a specific location. For example, ......
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