/** * This helps you transform the current GraphQLSchema object into another one by starting a builder with all * the current values and allows you to transform it how you want. * * @param builderConsumer the consumer code that will be given a builder to transform * * @return a new GraphQLSchema object based on calling build on that builder */ public GraphQLSchema transform(Consumer<Builder> builderConsumer) { Builder builder = newSchema(this); builderConsumer.accept(builder); return builder.build(); }
void creatingASchema() { GraphQLSchema schema = GraphQLSchema.newSchema() .query(queryType) // must be provided .mutation(mutationType) // is optional .build(); }
private void noIntrospection() { //::FigureK GraphQLSchema schema = GraphQLSchema.newSchema() .query(StarWarsSchema.queryType) .fieldVisibility(NoIntrospectionGraphqlFieldVisibility.NO_INTROSPECTION_FIELD_VISIBILITY) .build(); //::/FigureK }
public static GraphQLSchema createSchema() { GraphQLObjectType root = rootType(); return GraphQLSchema.newSchema() .query(root) .build(); }
GraphQLObjectType subscription; GraphQLSchema.Builder schemaBuilder = GraphQLSchema.newSchema();
private void blockedFields() { //::FigureJ GraphqlFieldVisibility blockedFields = BlockedFields.newBlock() .addPattern("Character.id") .addPattern("Droid.appearsIn") .addPattern(".*\\.hero") // it uses regular expressions .build(); GraphQLSchema schema = GraphQLSchema.newSchema() .query(StarWarsSchema.queryType) .fieldVisibility(blockedFields) .build(); //::/FigureJ }
public static void main(String[] args) { GraphQLObjectType queryType = newObject() .name("helloWorldQuery") .field(newFieldDefinition() .type(GraphQLString) .name("hello") .staticValue("world")) .build(); GraphQLSchema schema = GraphQLSchema.newSchema() .query(queryType) .build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); Map<String, Object> result = graphQL.execute("{hello}").getData(); System.out.println(result); // Prints: {hello=world} }
private void simpleQueryExecution() throws Exception { //::FigureA GraphQLSchema schema = GraphQLSchema.newSchema() .query(queryType) .build(); GraphQL graphQL = GraphQL.newGraphQL(schema) .build(); ExecutionInput executionInput = ExecutionInput.newExecutionInput().query("query { hero { name } }") .build(); ExecutionResult executionResult = graphQL.execute(executionInput); Object data = executionResult.getData(); List<GraphQLError> errors = executionResult.getErrors(); //::/FigureA }
@Test public void helloWorldTest() { GraphQLObjectType queryType = newObject() .name("helloWorldQuery") .field(newFieldDefinition() .type(GraphQLString) .name("hello") .staticValue("world")) .build(); GraphQLSchema schema = GraphQLSchema.newSchema() .query(queryType) .build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); Map<String, Object> result = graphQL.execute("{hello}").getData(); assertEquals("world", result.get("hello")); } }
.build(); indexSchema = GraphQLSchema.newSchema() .query(queryType) .build();
GraphQLSchema schema = GraphQLSchema.newSchema() .query(queryType) .mutation(createReviewForEpisodeMutation)
return GraphQLSchema.newSchema() .query(queryType) .additionalType(simpleObjectType)
@Test public void queryingOneFieldNotAnnotatedWithGraphQLInvokeDetachedAndNameIsPrettified_valueIsDeterminedByEntity() { GraphQLObjectType object = GraphQLAnnotations.object(Query.class); GraphQLSchema schema = newSchema().query(object).build(); ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("query { field { x } }"); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map<String, Map<String, Integer>>) result.getData()).get("field").get("x").toString(), "5"); }
@Test public void unionQueryWithCustomTypeResolver_askForDog_getDog() { GraphQLSchema schema = newSchema().query(GraphQLAnnotations.object(Query.class)).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); String query = "{ getPet(kindOfPet:\"dog\"){ ... on Cat {mew}, ... on Dog{waf}} }"; ExecutionResult result = graphQL.execute(query); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map<String, Map<String, String>>) result.getData()).get("getPet").get("waf"), "waf"); }
@Test public void unionQueryWithCustomTypeResolver_askForCat_getCat() { GraphQLSchema schema = newSchema().query(GraphQLAnnotations.object(Query.class)).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); String query = "{ getPet(kindOfPet:\"cat\"){ ... on Cat {mew}, ... on Dog{waf}} }"; ExecutionResult result = graphQL.execute(query); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map<String, Map<String, String>>) result.getData()).get("getPet").get("mew"), "mew"); }
@Test public void queryMultipleDefinitions() { GraphQLSchema schema = newSchema().query(GraphQLAnnotations.object(QueryMultipleDefinitions.class)).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); ExecutionResult result = graphQL.execute("{ something(code: {firstField:\"a\",secondField:\"b\"}) somethingElse(code: {firstField:\"c\",secondField:\"d\"}) }", new QueryMultipleDefinitions()); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map<String, String>) result.getData()).get("something"), "ab"); assertEquals(((Map<String, String>) result.getData()).get("somethingElse"), "cd"); }
@Test public void queryingFieldsFromNoApiEntityFetcher_noMatchingFieldInEntity_throwException() { GraphQLObjectType object = GraphQLAnnotations.object(Query.class); GraphQLSchema schema = newSchema().query(object).build(); ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("query { field { c } }"); assertFalse(result.getErrors().isEmpty()); assertTrue(((ExceptionWhileDataFetching) result.getErrors().get(0)).getException().getCause() instanceof NoSuchFieldException); } }
@Test public void queryName_directivesProvidedToRegistry_wiringIsActivated() throws Exception { GraphQLDirective upperCase = GraphQLAnnotations.directive(UpperCase.class); GraphQLObjectType object = GraphQLAnnotations.object(Query.class, upperCase); GraphQLSchema schema = newSchema().query(object).build(); ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("query { name }"); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map<String, String>) result.getData()).get("name").toString(), "YARIN"); }
@Test public void query_onlyApiClass_valueIsDeterminedByMethod() throws Exception { GraphQLObjectType object = GraphQLAnnotations.object(Query2.class); GraphQLSchema schema = newSchema().query(object).build(); ExecutionResult result = GraphQL.newGraphQL(schema).build().execute(builder -> builder.query("query { queryField { name } }").root(new Query2())); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map<String, Map<String, String>>) result.getData()).get("queryField").get("name").toString(), "guy"); }
@Test public void query() { GraphQLSchema schema = newSchema().query(GraphQLAnnotations.object(Query.class)) .additionalType(GraphQLAnnotations.object(TestObject.class)).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); ExecutionResult result = graphQL.execute("{ iface { value } }"); assertTrue(result.getErrors().isEmpty()); assertEquals(((Map<String, Map<String, String>>) result.getData()).get("iface").get("value"), "a"); }