builder.name(typeDefinition.getName()); builder.description(schemaGeneratorHelper.buildDescription(typeDefinition, typeDefinition.getDescription()));
return GraphQLObjectType.newObject() .name("Root") .field(GraphQLFieldDefinition.newFieldDefinition() .name("value")
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} }
@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(); }
public GraphQLSchemaBuilder() { this.rootQueryBuilder = GraphQLObjectType.newObject().name("Query").description("Root of Query Schema"); this.rootMutationBuilder = GraphQLObjectType.newObject().name("Mutation").description("Root of Mutation Schema"); this.defaultTypeConverters = getDefaultTypeConverters(); try { classLoader = getClass().getClassLoader(); classPath = ClassPath.from(classLoader); } catch (IOException ex) { Throwables.propagate(ex); } }
@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); }
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(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(); }
@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(); }
private GraphQLList buildEdgesObject(String relationName, GraphQLOutputType entityType) { return new GraphQLList(newObject() .name("__edges__" + relationName) .field(newFieldDefinition() .name("node") .dataFetcher(dataFetcher) .type(entityType)) .build()); }
.name("stopAtDistance") .field(GraphQLFieldDefinition.newFieldDefinition() .name("stop") .name("StoptimesInPattern") .field(GraphQLFieldDefinition.newFieldDefinition() .name("pattern") .name("Cluster") .withInterface(nodeInterface) .field(GraphQLFieldDefinition.newFieldDefinition() .name("Stop") .withInterface(nodeInterface) .field(GraphQLFieldDefinition.newFieldDefinition() .name("Stoptime") .field(GraphQLFieldDefinition.newFieldDefinition() .name("stop") .name("Trip") .withInterface(nodeInterface) .field(GraphQLFieldDefinition.newFieldDefinition() .name("Coordinates") .field(GraphQLFieldDefinition.newFieldDefinition() .name("lat") .name("Pattern")
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(); }
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(); }
@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 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(); }
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 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(); }
void recursiveTypes() { GraphQLObjectType person = newObject() .name("Person") .field(newFieldDefinition() .name("friends") .type(GraphQLList.list(GraphQLTypeReference.typeRef("Person")))) .build(); }