Java Code Examples for graphql.schema.GraphQLFieldDefinition#getType()
The following examples show how to use
graphql.schema.GraphQLFieldDefinition#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaToProto.java From rejoiner with Apache License 2.0 | 6 votes |
@SuppressWarnings("JdkObsolete") static Set<GraphQLType> getAllTypes(GraphQLSchema schema) { LinkedHashSet<GraphQLType> types = new LinkedHashSet<>(); LinkedList<GraphQLObjectType> loop = new LinkedList<>(); loop.add(schema.getQueryType()); types.add(schema.getQueryType()); while (!loop.isEmpty()) { for (GraphQLFieldDefinition field : loop.pop().getFieldDefinitions()) { GraphQLType type = field.getType(); if (type instanceof GraphQLList) { type = ((GraphQLList) type).getWrappedType(); } if (!types.contains(type)) { if (type instanceof GraphQLEnumType) { types.add(field.getType()); } if (type instanceof GraphQLObjectType) { types.add(type); loop.add((GraphQLObjectType) type); } } } } return types; }
Example 2
Source File: TypeGeneratorListOfListTest.java From graphql-java-type-generator with MIT License | 5 votes |
public static void assertClassWithListOfList(Object objectType) { Assert.assertThat(objectType, instanceOf(GraphQLObjectType.class)); Assert.assertThat(objectType, not(instanceOf(GraphQLList.class))); GraphQLFieldDefinition field = ((GraphQLObjectType) objectType) .getFieldDefinition("listOfListOfInts"); Assert.assertThat(field, notNullValue()); GraphQLOutputType outputType = field.getType(); assertListOfListOfInt(outputType); }
Example 3
Source File: TypeGeneratorListOfListTest.java From graphql-java-type-generator with MIT License | 5 votes |
@Test public void testGeneratedListOfListOfList() { logger.debug("testGeneratedListOfListOfList"); Object objectType = generator.getOutputType(ClassWithListOfListOfList.class); Assert.assertThat(objectType, instanceOf(GraphQLObjectType.class)); Assert.assertThat(objectType, not(instanceOf(GraphQLList.class))); GraphQLFieldDefinition field = ((GraphQLObjectType) objectType) .getFieldDefinition("listOfListOfListOfInts"); Assert.assertThat(field, notNullValue()); GraphQLOutputType listType = field.getType(); Assert.assertThat(listType, instanceOf(GraphQLList.class)); GraphQLType wrappedType = ((GraphQLList) listType).getWrappedType(); assertListOfListOfInt(wrappedType); }
Example 4
Source File: TypeGeneratorGenericsTest.java From graphql-java-type-generator with MIT License | 5 votes |
@Test public void testGeneratedListOfParam() { logger.debug("testGeneratedListOfParam"); Object objectType = generator.getOutputType(ClassWithListOfGenerics.class); Assert.assertThat(objectType, instanceOf(GraphQLObjectType.class)); Assert.assertThat(objectType, not(instanceOf(GraphQLList.class))); GraphQLFieldDefinition field = ((GraphQLObjectType) objectType) .getFieldDefinition("listOfParamOfInts"); Assert.assertThat(field, notNullValue()); GraphQLOutputType listType = field.getType(); Assert.assertThat(listType, instanceOf(GraphQLList.class)); GraphQLType wrappedType = ((GraphQLList) listType).getWrappedType(); Assert.assertThat(wrappedType, instanceOf(GraphQLObjectType.class)); }
Example 5
Source File: TypeGeneratorRawArrayTest.java From graphql-java-type-generator with MIT License | 5 votes |
public void assertListOfInt(Object objectType) { Assert.assertThat(objectType, instanceOf(GraphQLObjectType.class)); Assert.assertThat(objectType, not(instanceOf(GraphQLList.class))); GraphQLFieldDefinition fieldDefinition = ((GraphQLObjectType) objectType).getFieldDefinition("integers"); Assert.assertThat(fieldDefinition, notNullValue()); GraphQLOutputType outputType = fieldDefinition.getType(); Assert.assertThat(outputType, CoreMatchers.instanceOf(GraphQLList.class)); GraphQLType wrappedType = ((GraphQLList) outputType).getWrappedType(); Assert.assertThat(wrappedType, instanceOf(GraphQLScalarType.class)); Assert.assertThat((GraphQLScalarType)wrappedType, is(Scalars.GraphQLInt)); }
Example 6
Source File: GenericsTest.java From graphql-spqr with Apache License 2.0 | 5 votes |
@Test public void testMissingGenerics() { Type type = TypeFactory.parameterizedClass(EchoService.class, MissingGenerics.class); GraphQLSchema schema = new TestSchemaGenerator() .withValueMapperFactory(valueMapperFactory) .withOperationsFromSingleton(new EchoService(), type, new PublicResolverBuilder()) .withTypeTransformer(new DefaultTypeTransformer(true, true)) .withTypeAdapters(new MapToListTypeAdapter()) .generate(); GraphQLFieldDefinition query = schema.getQueryType().getFieldDefinition("echo"); GraphQLObjectType output = (GraphQLObjectType) query.getType(); assertMapOf(output.getFieldDefinition("raw").getType(), GraphQLScalarType.class, GraphQLScalarType.class); assertMapOf(output.getFieldDefinition("unbounded").getType(), GraphQLScalarType.class, GraphQLScalarType.class); GraphQLInputObjectType input = (GraphQLInputObjectType) query.getArgument("in").getType(); assertInputMapOf(input.getFieldDefinition("raw").getType(), GraphQLScalarType.class, GraphQLScalarType.class); assertInputMapOf(input.getFieldDefinition("unbounded").getType(), GraphQLScalarType.class, GraphQLScalarType.class); GraphQL runtime = GraphQL.newGraphQL(schema).build(); ExecutionResult result = runtime.execute("{" + "echo (in: {" + " raw: [{key: 2, value: 3}]" + " unbounded: [{key: 2, value: 3}]" + "}) {" + " raw {key, value}" + " unbounded {key, value}" + "}}"); assertNoErrors(result); assertValueAtPathEquals(2, result, "echo.raw.0.key"); assertValueAtPathEquals(3, result, "echo.raw.0.value"); assertValueAtPathEquals(2, result, "echo.unbounded.0.key"); assertValueAtPathEquals(3, result, "echo.unbounded.0.value"); }
Example 7
Source File: DirectiveTest.java From graphql-spqr with Apache License 2.0 | 5 votes |
@Test public void testSchemaDirectives() { GraphQLSchema schema = new TestSchemaGenerator() .withOperationsFromSingleton(new ServiceWithDirectives()) .generate(); GraphQLFieldDefinition scalarField = schema.getQueryType().getFieldDefinition("scalar"); assertDirective(scalarField, "fieldDef", "fieldDef"); GraphQLScalarType scalarResult = (GraphQLScalarType) scalarField.getType(); assertDirective(scalarResult, "scalar", "scalar"); graphql.schema.GraphQLArgument argument = scalarField.getArgument("in"); assertDirective(argument, "argDef", "argument"); GraphQLInputObjectType inputType = (GraphQLInputObjectType) argument.getType(); assertDirective(inputType, "inputObjectType", "input"); graphql.schema.GraphQLArgument directiveArg = DirectivesUtil.directiveWithArg(inputType.getDirectives(), "inputObjectType", "value").get(); Optional<graphql.schema.GraphQLArgument> metaArg = DirectivesUtil.directiveWithArg(directiveArg.getDirectives(), "meta", "value"); assertTrue(metaArg.isPresent()); assertEquals("meta", metaArg.get().getValue()); GraphQLInputObjectField inputField = inputType.getField("value"); assertDirective(inputField, "inputFieldDef", "inputField"); GraphQLFieldDefinition objField = schema.getQueryType().getFieldDefinition("obj"); GraphQLObjectType objResult = (GraphQLObjectType) objField.getType(); assertDirective(objResult, "objectType", "object"); GraphQLFieldDefinition innerField = objResult.getFieldDefinition("value"); assertDirective(innerField, "fieldDef", "field"); }
Example 8
Source File: TypeGeneratorGenericsTest.java From graphql-java-type-generator with MIT License | 4 votes |
@Test public void testWildcard() { logger.debug("testWildcard"); Object objectType = generator.getOutputType(WildcardGenericsClass.class); Assert.assertThat(objectType, instanceOf(GraphQLObjectType.class)); Assert.assertThat(objectType, not(instanceOf(GraphQLList.class))); //uncomment this to print out more data // GraphQLObjectType queryType = newObject() // .name("testQuery") // .field(newFieldDefinition() // .type((GraphQLOutputType) objectType) // .name("testObj") // .staticValue(new WildcardGenericsClass()) // .build()) // .build(); // GraphQLSchema testSchema = GraphQLSchema.newSchema() // .query(queryType) // .build(); // // ExecutionResult queryResult = new GraphQL(testSchema).execute(TypeGeneratorTest.querySchema); // assertThat(queryResult.getErrors(), is(empty())); // Map<String, Object> resultMap = (Map<String, Object>) queryResult.getData(); // if (logger.isDebugEnabled()) { // logger.debug("testWildcard resultMap {}", TypeGeneratorTest.prettyPrint(resultMap)); // } GraphQLFieldDefinition field = ((GraphQLObjectType) objectType) .getFieldDefinition("extendsInts"); Assert.assertThat(field, notNullValue()); GraphQLOutputType listType = field.getType(); Assert.assertThat(listType, instanceOf(GraphQLList.class)); GraphQLType wrappedType = ((GraphQLList) listType).getWrappedType(); Assert.assertThat(wrappedType, instanceOf(GraphQLScalarType.class)); Assert.assertThat((GraphQLScalarType)wrappedType, is(equalTo(Scalars.GraphQLInt))); field = ((GraphQLObjectType) objectType) .getFieldDefinition("superInts"); Assert.assertThat(field, notNullValue()); listType = field.getType(); Assert.assertThat(listType, instanceOf(GraphQLList.class)); wrappedType = ((GraphQLList) listType).getWrappedType(); Assert.assertThat(wrappedType, instanceOf(GraphQLObjectType.class)); Assert.assertThat((GraphQLObjectType)wrappedType, is(equalTo(DefaultTypes.getDefaultObjectType(Object.class)))); field = ((GraphQLObjectType) objectType) .getFieldDefinition("noBounds"); Assert.assertThat(field, notNullValue()); listType = field.getType(); Assert.assertThat(listType, instanceOf(GraphQLList.class)); wrappedType = ((GraphQLList) listType).getWrappedType(); Assert.assertThat(wrappedType, instanceOf(GraphQLObjectType.class)); Assert.assertThat((GraphQLObjectType)wrappedType, is(equalTo(DefaultTypes.getDefaultObjectType(Object.class)))); }