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} }
@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")); } }
public GraphQLType createType(GraphQLContext context) { Map<String, GraphQLObjectType> types = generateMicroschemaFieldType(context); // No microschemas have been found - We need to add a dummy type in order to keep the type system working if (types.isEmpty()) { types.put("dummy", newObject().name("dummy").field(newFieldDefinition().name("dummy").type(GraphQLString).staticValue(null).build()).description("Placeholder dummy microschema type").build()); } GraphQLObjectType[] typeArray = types.values().toArray(new GraphQLObjectType[types.values().size()]); GraphQLUnionType fieldType = newUnionType().name(MICRONODE_TYPE_NAME).possibleTypes(typeArray).description("Fields of the micronode.") .typeResolver(env -> { Object object = env.getObject(); if (object instanceof Micronode) { Micronode fieldContainer = (Micronode) object; MicroschemaContainerVersion micronodeFieldSchema = fieldContainer.getSchemaContainerVersion(); String schemaName = micronodeFieldSchema.getName(); GraphQLObjectType foundType = types.get(schemaName); return foundType; } return null; }).build(); return fieldType; }
.description("In which currency is the fare in ISO 4217 code") .type(new GraphQLNonNull(Scalars.GraphQLString)) .staticValue("USD") .build()) .build();
.description("In which currency is the fare in ISO 4217 code") .type(new GraphQLNonNull(Scalars.GraphQLString)) .staticValue("USD") .build()) .build();
GraphQLFieldDefinition.Builder rootViewField = GraphQLFieldDefinition.newFieldDefinition().name(graphQLController.rootQueriesObjectName()).staticValue(queryHandler); GraphQLFieldDefinition.Builder rootMutationField = GraphQLFieldDefinition.newFieldDefinition().name(graphQLController.rootMutationsObjectName()).staticValue(queryHandler);
.name("viewer") .type(userType) .staticValue(theOnlyUser) .build()) .field(relay.nodeField(nodeInterface, todoDataFetcher))
fieldBuilder.staticValue(fieldFetcher);
@Test public void testArrayStartsWith() throws Exception { GraphQLObjectType innerType = newObject() .name("Inner") .field(newStringField("b").staticValue("foo")) .build(); GraphQLSchema schema = newQuerySchema(it -> it .field( newField("a", new GraphQLList(innerType)) .dataFetcher(env -> Flowable .just(asList(true, true, true)) .delay(1, SECONDS, scheduler) .startWith(new ArrayList<Boolean>()) ) ) ); ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a { b } }"); Flowable.fromPublisher((Publisher<Change>) executionResult.getData()).timestamp(scheduler).subscribe(subscriber); scheduler.advanceTimeBy(2, SECONDS); subscriber .assertChanges(it -> it.containsExactly( tuple("00:000", "", ImmutableMap.of("a", emptyList())), tuple("01:000", "a", asList(ImmutableMap.of("b", "foo"), ImmutableMap.of("b", "foo"), ImmutableMap.of("b", "foo"))), // FIXME this values are duplicated. For now, let's call it "at least once" delivery :D tuple("01:000", "a[1]", ImmutableMap.of("b", "foo")), tuple("01:000", "a[2]", ImmutableMap.of("b", "foo")) )) .assertComplete(); }
.type(GraphQLString) .name("hello") .staticValue(Observable.just("world")) .build()) .build();
public GraphQLFieldDefinition getFieldDefinition(DfsContext dfsContext, Class<?> implClass, Field field) { GraphQLFieldDefinition graphQLFieldDefinition = null; ResolvableTypeAccessor resolvableTypeAccessor = ResolvableTypeAccessor.forField(field, implClass); if (resolvableTypeAccessor.isNotIgnorable()) { GraphQLOutputType graphQLOutputType = (GraphQLOutputType) createGraphQLFieldType(dfsContext, resolvableTypeAccessor, true); GraphQLFieldDefinition.Builder graphQLFieldDefinitionBuilder = GraphQLFieldDefinition.newFieldDefinition() .name(resolvableTypeAccessor.getName()) .type(graphQLOutputType) .deprecate(resolvableTypeAccessor.getGraphQLDeprecationReason()) .description(resolvableTypeAccessor.getDescription()); boolean isConstant = Modifier.isFinal(field.getModifiers()) && Modifier.isStatic(field.getModifiers()); if (isConstant) { graphQLFieldDefinitionBuilder.staticValue(org.springframework.util.ReflectionUtils.getField(field, null)); } graphQLFieldDefinition = graphQLFieldDefinitionBuilder.build(); addToFieldDefinitionResolverMap(dfsContext, graphQLFieldDefinition, resolvableTypeAccessor.getGraphQLComplexitySpelExpression()); } return graphQLFieldDefinition; }
public static void main(String[] args) { GraphQLObjectType queryType = newObject() .name("helloWorldQuery") .field(newFieldDefinition() .type(GraphQLString) .name("hello") .staticValue(Observable.just("world")) .build()) .build(); GraphQLSchema schema = GraphQLSchema.newSchema() .query(queryType) .build(); Observable<?> result = ((RxExecutionResult)new GraphQL(schema, new RxExecutionStrategy()).execute("{hello}")).getDataObservable(); result.subscribe(System.out::println); }
@Override public void build (Builder aBuilder) { aBuilder.field(Fields.stringField("ping").staticValue("OK")); }
private GraphQLFieldDefinition getViewerField() { GraphQLFieldDefinition viewer = newFieldDefinition() .name("viewer") .type(todoSchema.getUserType()) .staticValue(todoSchema.getTheOnlyUser()) .build(); return viewer; }
private GraphQLSchema generateGettingStartedGraphQlSchema() { val gettingStartedType = newObject() .name("gettingStartedQuery") .field(newFieldDefinition() .type(GraphQLString) .name("gettingStarted") .staticValue("Create a component and implement GraphQlFields interface.")) .build(); return GraphQLSchema.newSchema() .query(gettingStartedType) .build(); } }
@Override public List<GraphQLFieldDefinition> getQueryFields() { return Collections.singletonList( newFieldDefinition() .type(GraphQLString) .name("hello") .staticValue("world") .build() ); }