Skip to content

directive #16

@mmjd

Description

@mmjd

I am trying to use directive in the following code example but if raises error.

GraphQLObjectType d = newObject()
                .name("Data")
                .field(newFieldDefinition()
                        .name("ID")
                        .type(GraphQLFloat)
                        .build())
                        .field(newFieldDefinition()
                                .name("Name")
                                .type(GraphQLString)
                                .build())
                                .build();

        GraphQLObjectType pageObject = newObject()
                .name("Page")
                .field(newFieldDefinition()
                        .name("Data")
                        .type(d)
                        .argument(
                                GraphQLArgument.newArgument()
                                .name("ID")
                                .type(GraphQLFloat)
                                .build()
                                )
                                .argument(
                                        GraphQLArgument.newArgument()
                                        .name("Name")
                                        .type(GraphQLString)
                                        .build()
                                        )
                                        .dataFetcher(new DataFetcher() {
                                            @Override
                                            public Object get(DataFetchingEnvironment environment) {

                                                Map<String, Object> arguments = environment.getArguments();
                                                Float id = (Float) arguments.get("ID");
                                                String name = (String) arguments.get("Name");

                                                Map<String, Object> result = new HashMap<String, Object>();
                                                result.put("ID", id);
                                                result.put("Name", name);
                                                return result;
                                            }
                                        })
                                        .build()
                        )
                        .build();


        GraphQLObjectType query = newObject()
                .name("sample")
                .field(newFieldDefinition()
                        .name("Page")
                        .type(pageObject)
                        .staticValue(pageObject)
                        .build())
                        .build();

        GraphQLSchema schema = GraphQLSchema.newSchema()
                .query(query)
                .build();

        System.out.println("Schema: " + schema.toString());
        //@include(Name: \"my\")
        String input = "query sample ($id: Float = 1.0, $name: String, $condition: Boolean) "
                + "{ Page { Data (ID: $id, Name:$name)  { ID , Name @skip(if: $condition) } } }";

        Map<String, Object> arguments = new HashMap<String, Object>();
        arguments.put("id", "2");
        arguments.put("name", "myName");
        arguments.put("condition", false);
        ExecutionResult result = new GraphQL(schema).execute(input, new Object(), arguments );
ValidationError{validationErrorType=MissingDirectiveArgument, sourceLocations=[SourceLocation{line=1, column=105}], description='Missing directive argument skip'}
ValidationError{validationErrorType=UnknownArgument, sourceLocations=[SourceLocation{line=1, column=111}], description='Unknown argument if'}
ValidationError{validationErrorType=VariableTypeMismatch, sourceLocations=[SourceLocation{line=1, column=115}], description='Variable type doesn't match'}

would you please tell me what is the problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions