Search in sources :

Example 1 with GraphQLString

use of graphql.Scalars.GraphQLString in project graphql-java by graphql-java.

the class FunWithStringsSchemaFactory method createSchema.

GraphQLSchema createSchema() {
    GraphQLObjectType stringObjectType = newObject().name("StringObject").field(newFieldDefinition().name("value").type(GraphQLString).dataFetcher(stringObjectValueFetcher)).field(newFieldDefinition().name("nonNullValue").type(new GraphQLNonNull(GraphQLString)).dataFetcher(stringObjectValueFetcher)).field(newFieldDefinition().name("veryNonNullValue").type(new GraphQLNonNull(new GraphQLNonNull(GraphQLString))).dataFetcher(stringObjectValueFetcher)).field(newFieldDefinition().name("throwException").type(GraphQLString).dataFetcher(throwExceptionFetcher)).field(newFieldDefinition().name("returnBadList").type(GraphQLString).dataFetcher(returnBadListFetcher)).field(newFieldDefinition().name("anyIterable").type(new GraphQLList(GraphQLString)).dataFetcher(anyIterableFetcher)).field(newFieldDefinition().name("shatter").type(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(new GraphQLTypeReference("StringObject"))))).dataFetcher(shatterFetcher)).field(newFieldDefinition().name("wordsAndLetters").type(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(new GraphQLNonNull(new GraphQLTypeReference("StringObject")))))))).dataFetcher(wordsAndLettersFetcher)).field(newFieldDefinition().name("split").description("String#split(regex) but replace empty strings with nulls to help us test null behavior in lists").type(new GraphQLList(new GraphQLTypeReference("StringObject"))).argument(GraphQLArgument.newArgument().name("regex").type(GraphQLString)).dataFetcher(splitFetcher)).field(newFieldDefinition().name("splitNotNull").description("String#split(regex) but replace empty strings with nulls to help us test null behavior in lists").type(new GraphQLList(new GraphQLNonNull(new GraphQLTypeReference("StringObject")))).argument(GraphQLArgument.newArgument().name("regex").type(GraphQLString)).dataFetcher(splitFetcher)).field(newFieldDefinition().name("append").type(new GraphQLTypeReference("StringObject")).argument(GraphQLArgument.newArgument().name("text").type(GraphQLString)).dataFetcher(appendFetcher)).field(newFieldDefinition().name("emptyOptional").type(GraphQLString).argument(GraphQLArgument.newArgument().name("text").type(GraphQLString)).dataFetcher(emptyOptionalFetcher)).field(newFieldDefinition().name("optional").type(GraphQLString).argument(GraphQLArgument.newArgument().name("text").type(GraphQLString)).dataFetcher(optionalFetcher)).field(newFieldDefinition().name("completableFuture").type(GraphQLString).argument(GraphQLArgument.newArgument().name("text").type(GraphQLString)).dataFetcher(completableFutureFetcher)).build();
    GraphQLEnumType enumDayType = newEnum().name("Day").value("MONDAY").value("TUESDAY").description("Day of the week").build();
    GraphQLObjectType simpleObjectType = newObject().name("SimpleObject").field(newFieldDefinition().name("value").type(GraphQLString)).build();
    GraphQLInterfaceType interfaceType = newInterface().name("InterfaceType").field(newFieldDefinition().name("value").type(GraphQLString)).typeResolver(env -> {
        // always this for testing
        return simpleObjectType;
    }).build();
    GraphQLObjectType queryType = newObject().name("StringQuery").field(newFieldDefinition().name("string").type(stringObjectType).argument(GraphQLArgument.newArgument().name("value").type(GraphQLString)).dataFetcher(env -> env.getArgument("value"))).field(newFieldDefinition().name("interface").type(interfaceType).argument(GraphQLArgument.newArgument().name("value").type(GraphQLString)).dataFetcher(env -> CompletableFuture.completedFuture(new SimpleObject()))).field(newFieldDefinition().name("nullEnum").type(enumDayType).dataFetcher(env -> null)).build();
    return GraphQLSchema.newSchema().query(queryType).build();
}
Also used : GraphQLList(graphql.schema.GraphQLList) GraphQLObjectType(graphql.schema.GraphQLObjectType) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) Arrays(java.util.Arrays) GraphQLString(graphql.Scalars.GraphQLString) GraphQLNonNull(graphql.schema.GraphQLNonNull) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) CompletableFuture(java.util.concurrent.CompletableFuture) GraphQLInterfaceType.newInterface(graphql.schema.GraphQLInterfaceType.newInterface) GraphQLArgument(graphql.schema.GraphQLArgument) ArrayList(java.util.ArrayList) GraphQLFieldDefinition.newFieldDefinition(graphql.schema.GraphQLFieldDefinition.newFieldDefinition) List(java.util.List) GraphQLList(graphql.schema.GraphQLList) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GraphQLEnumType.newEnum(graphql.schema.GraphQLEnumType.newEnum) Map(java.util.Map) GraphQLObjectType.newObject(graphql.schema.GraphQLObjectType.newObject) DataFetcher(graphql.schema.DataFetcher) GraphQLSchema(graphql.schema.GraphQLSchema) Optional(java.util.Optional) GraphQLEnumType(graphql.schema.GraphQLEnumType) ArrayDeque(java.util.ArrayDeque) LinkedHashSet(java.util.LinkedHashSet) GraphQLTypeReference(graphql.schema.GraphQLTypeReference) GraphQLEnumType(graphql.schema.GraphQLEnumType) GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLNonNull(graphql.schema.GraphQLNonNull) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType)

Example 2 with GraphQLString

use of graphql.Scalars.GraphQLString in project graphql-java by graphql-java.

the class HelloWorld method main.

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}
}
Also used : GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLObjectType.newObject(graphql.schema.GraphQLObjectType.newObject) GraphQLString(graphql.Scalars.GraphQLString) GraphQLSchema(graphql.schema.GraphQLSchema)

Example 3 with GraphQLString

use of graphql.Scalars.GraphQLString in project graphql-java by graphql-java.

the class HelloWorld method helloWorldTest.

@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"));
}
Also used : GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLObjectType.newObject(graphql.schema.GraphQLObjectType.newObject) GraphQLString(graphql.Scalars.GraphQLString) GraphQLSchema(graphql.schema.GraphQLSchema) Test(org.junit.Test)

Aggregations

GraphQLString (graphql.Scalars.GraphQLString)3 GraphQLObjectType (graphql.schema.GraphQLObjectType)3 GraphQLObjectType.newObject (graphql.schema.GraphQLObjectType.newObject)3 GraphQLSchema (graphql.schema.GraphQLSchema)3 DataFetcher (graphql.schema.DataFetcher)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 GraphQLArgument (graphql.schema.GraphQLArgument)1 GraphQLEnumType (graphql.schema.GraphQLEnumType)1 GraphQLEnumType.newEnum (graphql.schema.GraphQLEnumType.newEnum)1 GraphQLFieldDefinition.newFieldDefinition (graphql.schema.GraphQLFieldDefinition.newFieldDefinition)1 GraphQLInterfaceType (graphql.schema.GraphQLInterfaceType)1 GraphQLInterfaceType.newInterface (graphql.schema.GraphQLInterfaceType.newInterface)1 GraphQLList (graphql.schema.GraphQLList)1 GraphQLNonNull (graphql.schema.GraphQLNonNull)1 GraphQLTypeReference (graphql.schema.GraphQLTypeReference)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1