- Common ways to obtain GraphQLObjectType$Builder
private void myMethod () {GraphQLObjectType$Builder g =
String str2;String str;GraphQLObjectType.newObject().name(str2).description(str)
String str;GraphQLObjectType.newObject().name(str)
- Smart code suggestions by Codota
}
.name("stopAtDistance") .field(GraphQLFieldDefinition.newFieldDefinition() .name("stop") .type(stopType) .dataFetcher(environment -> ((GraphIndex.StopAndDistance) environment.getSource()).stop) .build()) .field(GraphQLFieldDefinition.newFieldDefinition() .name("distance") .type(Scalars.GraphQLInt) .dataFetcher(environment -> ((GraphIndex.StopAndDistance) environment.getSource()).distance) .build()) .build(); .name("StoptimesInPattern") .field(GraphQLFieldDefinition.newFieldDefinition() .name("pattern") .type(patternType) .get(((StopTimesInPattern) environment.getSource()).pattern.id)) .build()) .field(GraphQLFieldDefinition.newFieldDefinition() .name("stoptimes") .type(new GraphQLList(stoptimeType)) .dataFetcher(environment -> ((StopTimesInPattern) environment.getSource()).times) .build()) .build(); .name("Cluster") .withInterface(nodeInterface)
@Override protected GraphQLObjectType toGraphQLType(String typeName, AnnotatedType javaType, OperationMapper operationMapper, BuildContext buildContext) { GraphQLObjectType.Builder builder = GraphQLObjectType.newObject() .name(typeName) .description(buildContext.typeInfoGenerator.generateTypeDescription(javaType, buildContext.messageBundle)); Enum<E>[] keys = ClassUtils.<E>getRawType(getElementType(javaType, 0).getType()).getEnumConstants(); Arrays.stream(keys).forEach(enumValue -> builder.field(GraphQLFieldDefinition.newFieldDefinition() .name(enumMapper.getValueName(enumValue, buildContext.messageBundle)) .description(enumMapper.getValueDescription(enumValue, buildContext.messageBundle)) .deprecate(enumMapper.getValueDeprecationReason(enumValue, buildContext.messageBundle)) .type(operationMapper.toGraphQLType(getElementType(javaType, 1), buildContext)) .dataFetcher(env -> ((Map)env.getSource()).get(enumValue)) .build())); return builder.build(); }
public GraphQLObjectType edgeType(String name, GraphQLOutputType nodeType, GraphQLInterfaceType nodeInterface, List<GraphQLFieldDefinition> edgeFields) { return newObject() .name(name + "Edge") .description("An edge in a connection") .field(newFieldDefinition() .name("node") .type(nodeType) .description("The item at the end of the edge")) .field(newFieldDefinition() .name("cursor") .type(nonNull(GraphQLString)) .description("cursor marks a unique position or index into the connection")) .fields(edgeFields) .build(); }
public Builder subscription(GraphQLObjectType.Builder builder) { return subscription(builder.build()); }
public static GraphQLObjectType.Builder elementTypeBuilder () { return objectTypeBuilder().withInterface(IElement.REF) .field(Fields.notNullStringField("id")); }
/** * This helps you transform the current GraphQLObjectType 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 object based on calling build on that builder */ public GraphQLObjectType transform(Consumer<Builder> builderConsumer) { Builder builder = newObject(this); builderConsumer.accept(builder); return builder.build(); }
@Override public void build (Builder aBuilder) { aBuilder.field(Fields.field("addDirector") .type(Director.REF) .argument(Arguments.notNullStringArgument("name")) .dataFetcher((env) -> { Node node = SimpleNode.builder(g) .type(Director.NAME) .properties(env.getArguments()) .build(); return g.add(node); })); }
@Override public void build (Builder aBuilder) { aBuilder.field(Fields.stringField("ping").staticValue("OK")); }
public GraphQLObjectType connectionType(String name, GraphQLObjectType edgeType, List<GraphQLFieldDefinition> connectionFields) { return newObject() .name(name + "Connection") .description("A connection to a list of items.") .field(newFieldDefinition() .name("edges") .description("a list of edges") .type(list(edgeType))) .field(newFieldDefinition() .name("pageInfo") .description("details about this specific page") .type(nonNull(pageInfoType))) .fields(connectionFields) .build(); }
@Test public void testCompletableFuture() throws Exception { ReactiveExecutionStrategy strategy = new ReactiveExecutionStrategy(); GraphQLSchema schema = newQuerySchema(it -> it .field(newStringField("a").dataFetcher(env -> CompletableFuture.completedFuture("static"))) ); ExecutionResult executionResult = new GraphQL(schema, strategy).execute("{ a }"); Flowable.fromPublisher((Publisher<Change>) executionResult.getData()).timestamp(scheduler).subscribe(subscriber); subscriber .assertChanges(it -> it.containsExactly( tuple("00:000", "", ImmutableMap.of("a", "static")) )) .assertComplete(); }
@Test(expectedExceptions = InvalidDirectiveLocationException.class) public void wireGraphQLUnionType_invalidLocations_exceptionIsThrown() throws Exception { // Arrange AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); GraphQLUnionType directiveContainer = GraphQLUnionType.newUnionType().name("asdf") .possibleType(GraphQLObjectType.newObject().name("Asdfaaaa").build()).typeResolver(env -> null).build(); AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, directiveContainer.getDirective("upperCase")); when(upperWiring.onUnion(upperCaseEnv)).thenReturn(directiveContainer); HashMap<GraphQLDirective, AnnotationsDirectiveWiring> map = new HashMap<>(); GraphQLDirective upperCase = newDirective().name("upperCase").build(); map.put(upperCase, upperWiring); // Act directiveWirer.wire(directiveContainer, map); }
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(); } }
private GraphQLObjectType getObjectType(EntityType<?> entityType) { if (entityCache.containsKey(entityType)) return entityCache.get(entityType); GraphQLObjectType objectType = GraphQLObjectType.newObject() .name(entityType.getName()) .description(getSchemaDescription( entityType.getJavaType())) .fields(entityType.getAttributes().stream() .filter(this::isNotIgnored) .map(this::getObjectField) .collect(Collectors.toList()) ) .build(); entityCache.putIfAbsent(entityType, objectType); return objectType; }
@Test(expectedExceptions = InvalidDirectiveLocationException.class) public void wireGraphQLObjectType_invalidLocations_exceptionIsThrown() throws Exception { // Arrange AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); GraphQLObjectType directiveContainer = GraphQLObjectType.newObject().name("asdf00").build(); AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, directiveContainer.getDirective("upperCase")); when(upperWiring.onObject(upperCaseEnv)).thenReturn(directiveContainer); HashMap<GraphQLDirective, AnnotationsDirectiveWiring> map = new HashMap<>(); GraphQLDirective upperCase = newDirective().name("upperCase").build(); map.put(upperCase, upperWiring); // Act directiveWirer.wire(directiveContainer, map); }
@Before public void setup() { expectedObjectType = GraphQLObjectType.newObject() .name(CollectionsTestObject.class.getSimpleName()) .field(GraphQLFieldDefinition.newFieldDefinition().name("field1").type(Scalars.GraphQLString).build()) .field(GraphQLFieldDefinition.newFieldDefinition().name("field2").type(Scalars.GraphQLInt).build()) .build(); graphQLObjectMapper = new GraphQLObjectMapper(objectMapper, GraphQLSchemaBuilder.getDefaultTypeMappers(), Optional.<ITypeNamingStrategy>absent(), Optional.<IDataFetcherFactory>absent(), Optional.<Class<? extends IDataFetcher>>absent(), GraphQLSchemaBuilder.getDefaultTypeConverters(), ImmutableList.<Class<?>> of()); }
@Override public GraphQLOutputType getOutputType(IGraphQLObjectMapper objectMapper, Type type) { return GraphQLObjectType.newObject().name(objectMapper.getTypeNamingStrategy().getTypeName(objectMapper, type)) .field(GraphQLFieldDefinition.newFieldDefinition().name("time").type(Scalars.GraphQLString).build()).build(); }
private GraphQLOutputType getListOutputMapping(final IGraphQLObjectMapper graphQLObjectMapper, final Type type) { ParameterizedType pType = (ParameterizedType) type; GraphQLObjectType objectType = GraphQLObjectType.newObject() .name(graphQLObjectMapper.getTypeNamingStrategy().getTypeName(graphQLObjectMapper, type)) .field(GraphQLFieldDefinition.newFieldDefinition() .name(KEY_NAME) .type(graphQLObjectMapper.getOutputType(pType.getActualTypeArguments()[0])) .build()) .field(GraphQLFieldDefinition.newFieldDefinition() .name(VALUE_NAME) .type(graphQLObjectMapper.getOutputType(pType.getActualTypeArguments()[1])) .build()) .build(); return new GraphQLList(objectType); }
protected GraphQLSchema newQuerySchema(Consumer<GraphQLObjectType.Builder> queryConsumer) { GraphQLObjectType.Builder queryType = newObject().name("QueryType"); queryConsumer.accept(queryType); return newSchema().query(queryType).build(); } }
public GraphQLObjectType createFocalPointType() { Builder type = newObject().name("FocalPoint").description("Focal point"); // .x type.field(newFieldDefinition().name("x").description("X-axis factor of the focal point. Left is 0 and middle is 0.5.").type(GraphQLFloat) .dataFetcher(fetcher -> { FocalPoint point = fetcher.getSource(); return point.getX(); })); // .y type.field(newFieldDefinition().name("y").description("Y-axis factor of the focal point. Top is 0 and middle is 0.5.").type(GraphQLFloat) .dataFetcher(fetcher -> { FocalPoint point = fetcher.getSource(); return point.getY(); })); return type.build(); }