/** * 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(); }
private GraphQLObjectType buildObjectType(BuildContext buildCtx, ObjectTypeDefinition typeDefinition) { buildCtx.enterNode(typeDefinition); GraphQLObjectType.Builder builder = GraphQLObjectType.newObject(); builder.definition(typeDefinition); builder.name(typeDefinition.getName());
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(); }
void recursiveTypes() { GraphQLObjectType person = newObject() .name("Person") .field(newFieldDefinition() .name("friends") .type(GraphQLList.list(GraphQLTypeReference.typeRef("Person")))) .build(); }
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(); }
void dataFetching() { DataFetcher<Foo> fooDataFetcher = new DataFetcher<Foo>() { @Override public Foo get(DataFetchingEnvironment environment) { // environment.getSource() is the value of the surrounding // object. In this case described by objectType Foo value = perhapsFromDatabase(); // Perhaps getting from a DB or whatever return value; } }; GraphQLObjectType objectType = newObject() .name("ObjectType") .field(newFieldDefinition() .name("foo") .type(GraphQLString) .dataFetcher(fooDataFetcher)) .build(); }
@SuppressWarnings("unchecked") public static GraphQLObjectType rootType() { return GraphQLObjectType.newObject()
public GraphQLFieldDefinition mutation(String name, String fieldName, List<GraphQLInputObjectField> inputFields, List<GraphQLFieldDefinition> outputFields, DataFetcher dataFetcher) { GraphQLInputObjectType inputObjectType = newInputObject() .name(name + "Input") .fields(inputFields) .build(); GraphQLObjectType outputType = newObject() .name(name + "Payload") .fields(outputFields) .build(); return newFieldDefinition() .name(fieldName) .type(outputType) .argument(newArgument() .name("input") .type(nonNull(inputObjectType))) .dataFetcher(dataFetcher) .build(); }
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")); } }
void newType() { GraphQLObjectType simpsonCharacter = newObject() .name("SimpsonCharacter") .description("A Simpson character") .field(newFieldDefinition() .name("name") .description("The name of the character.") .type(GraphQLString)) .field(newFieldDefinition() .name("mainCharacter") .description("One of the main Simpson characters?") .type(GraphQLBoolean)) .build(); }
stopAtDistanceType = GraphQLObjectType.newObject() .name("stopAtDistance") .field(GraphQLFieldDefinition.newFieldDefinition() stoptimesInPatternType = GraphQLObjectType.newObject() .name("StoptimesInPattern") .field(GraphQLFieldDefinition.newFieldDefinition() clusterType = GraphQLObjectType.newObject() .name("Cluster") .withInterface(nodeInterface) stopType = GraphQLObjectType.newObject() .name("Stop") .withInterface(nodeInterface) stoptimeType = GraphQLObjectType.newObject() .name("Stoptime") .field(GraphQLFieldDefinition.newFieldDefinition() tripType = GraphQLObjectType.newObject() .name("Trip") .withInterface(nodeInterface) coordinateType = GraphQLObjectType.newObject() .name("Coordinates") .field(GraphQLFieldDefinition.newFieldDefinition() patternType = GraphQLObjectType.newObject()
GraphQLSchema createSchema() { GraphQLObjectType stringObjectType = newObject() .name("StringObject") .field(newFieldDefinition() GraphQLObjectType simpleObjectType = newObject() .name("SimpleObject") .withInterface(typeRef("InterfaceType")) .build(); GraphQLObjectType queryType = newObject() .name("StringQuery") .field(newFieldDefinition()
@PostConstruct public void postConstruct() { GraphQLObjectType.Builder queryBuilder = newObject().name(properties.getRootQueryName()); GraphQLObjectType.Builder mutationBuilder = newObject().name(properties.getRootMutationName()); if (StringUtils.hasText(properties.getRootQueryDescription())) { queryBuilder = queryBuilder.description(properties.getRootQueryDescription()); } if (StringUtils.hasText(properties.getRootMutationDescription())) { mutationBuilder = mutationBuilder.description(properties.getRootMutationDescription()); } buildSchemaFromDefinitions(queryBuilder, mutationBuilder); }
private GraphQLList buildEdgesObject(String relationName, GraphQLOutputType entityType) { return new GraphQLList(newObject() .name("__edges__" + relationName) .field(newFieldDefinition() .name("node") .dataFetcher(dataFetcher) .type(entityType)) .build()); }
public GraphQLObjectType createType() { GraphQLObjectType.Builder root = newObject(); root.name(PROJECT_REFERENCE_TYPE_NAME); interfaceTypeProvider.addCommonFields(root); // .name root.field(newFieldDefinition().name("name").description("The name of the project").type(GraphQLString)); return root.build(); } }
@Override public GraphQLObjectType createType(GQLTypeCache cache) { return newObject() .name(PROPERTY_TYPE) .field(GraphqlUtils.stringField("typeName", "Qualified type name")) .field(GraphqlUtils.stringField("name", "Display type name")) .field(GraphqlUtils.stringField("description", "Short description for the type")) .build(); }
@Override public GraphQLObjectType createType(GQLTypeCache cache) { return newObject() .name(PROJECT_ROLE) .field(GraphqlUtils.stringField("id", "ID of the role")) .field(GraphqlUtils.nameField("Unique name for the role")) .field(GraphqlUtils.stringField("description", "Description of the role")) .build(); }
@Override public GraphQLObjectType createType(GQLTypeCache cache) { return newObject() .name(ACCOUNT_GROUP_MAPPING) .field(GraphqlUtils.idField()) .field(GraphqlUtils.stringField("name", "Name of the mapping")) .field(GraphqlUtils.stringField("type", "Type of the mapping")) .field(f -> f.name("group") .description("Associated group") .type(new GraphQLTypeReference(GQLTypeAccountGroup.ACCOUNT_GROUP))) .build(); }