@SuppressWarnings("unchecked") public Builder(GraphQLFieldDefinition existing) { this.name = existing.getName(); this.description = existing.getDescription(); this.type = existing.getType(); this.dataFetcherFactory = DataFetcherFactories.useDataFetcher(existing.getDataFetcher()); this.deprecationReason = existing.getDeprecationReason(); this.definition = existing.getDefinition(); this.arguments.putAll(getByName(existing.getArguments(), GraphQLArgument::getName)); this.directives.putAll(getByName(existing.getDirectives(), GraphQLDirective::getName)); }
@Override public GraphQLInputObjectType getInputObject(GraphQLObjectType graphQLType, String newNamePrefix) { GraphQLObjectType object = graphQLType; return new GraphQLInputObjectType("" + newNamePrefix + object.getName(), object.getDescription(), object.getFieldDefinitions().stream(). map(field -> { GraphQLOutputType type = field.getType(); GraphQLInputType inputType; if (type instanceof GraphQLObjectType) { inputType = getInputObject((GraphQLObjectType) type, newNamePrefix); } else { inputType = (GraphQLInputType) type; } return new GraphQLInputObjectField(field.getName(), field.getDescription(), inputType, null); }). collect(Collectors.toList())); }
public GraphQLFieldDefinitionWrapper(GraphQLFieldDefinition fieldDefinition) { super(fieldDefinition.getName(), fieldDefinition.getDescription(), fieldDefinition.getType(), fieldDefinition.getDataFetcher(), fieldDefinition.getArguments(), fieldDefinition.getDeprecationReason()); }
@SuppressWarnings("unchecked") public Builder(GraphQLFieldDefinition existing) { this.name = existing.getName(); this.description = existing.getDescription(); this.type = existing.getType(); this.dataFetcherFactory = DataFetcherFactories.useDataFetcher(existing.getDataFetcher()); this.deprecationReason = existing.getDeprecationReason(); this.definition = existing.getDefinition(); this.arguments.putAll(getByName(existing.getArguments(), GraphQLArgument::getName)); this.directives.putAll(getByName(existing.getDirectives(), GraphQLDirective::getName)); }
assertEquals(fields.get(2).getDescription(), "field"); assertTrue(fields.get(2).getType() instanceof graphql.schema.GraphQLNonNull); assertEquals(((graphql.schema.GraphQLNonNull) fields.get(2).getType()).getWrappedType(), GraphQLString);
public GraphQLFieldDefinitionWrapper(GraphQLFieldDefinition fieldDefinition) { super(fieldDefinition.getName(), fieldDefinition.getDescription(), fieldDefinition.getType(), DataFetcherFactories.useDataFetcher((DataFetcher<?>) fieldDefinition.getDataFetcher()), fieldDefinition.getArguments(), fieldDefinition.getDeprecationReason(), fieldDefinition.getDirectives(), fieldDefinition.getDefinition()); }
private GraphQLInputType getInputType(GraphQLOutputType outputType) { if (GraphQLInputType.class.isAssignableFrom(outputType.getClass())) { return (GraphQLInputType) outputType; } else if (outputType instanceof GraphQLObjectType) { GraphQLObjectType objectType = (GraphQLObjectType) outputType; final String inputTypeName; inputTypeName = String.format("%s%s%s", objectType.getName(), this.getTypeNamingStrategy().getDelimiter(), this.getTypeNamingStrategy().getInputTypePostfix()); GraphQLInputObjectType.Builder rv = GraphQLInputObjectType.newInputObject().name(inputTypeName); rv.description(((GraphQLObjectType) outputType).getDescription()); for (GraphQLFieldDefinition field : objectType.getFieldDefinitions()) { rv.field(GraphQLInputObjectField.newInputObjectField() .name(field.getName()) .type(getInputType(field.getType())) .description(field.getDescription()) .build()); } GraphQLInputType type = rv.build(); inputTypes.add(type); return type; } else { throw new RuntimeException(String.format("Unknown output type %s", outputType.toString())); } }
@Test public void testDocumentedAttributes() { IGraphQLObjectMapper graphQLObjectMapper = newGraphQLObjectMapper( ImmutableList.<IGraphQLTypeMapper> builder().addAll(GraphQLSchemaBuilder.getDefaultTypeMappers()).build()); GraphQLObjectType objectType = (GraphQLObjectType) graphQLObjectMapper.getOutputType(new TypeToken<TestDocumentationClass>() { }.getType()); assertNotNull(objectType.getFieldDefinition("field")); assertEquals("The class description",objectType.getDescription()); assertEquals("The field description", objectType.getFieldDefinition("field").getDescription()); assertEquals("The method description", objectType.getFieldDefinition("value").getDescription()); }
public static GraphQLSubscription subscription(GraphQLFieldDefinition definition){ final String id = generateId(); final GraphQLSubscription subscription = new GraphQLSubscription(); subscription.setId(id); subscription.setName(definition.getName()); subscription.setDescription(definition.getDescription()); subscription.setResponseStrategy(GraphQLResponseStrategy.RANDOM); subscription.setStatus(GraphQLOperationStatus.MOCKED); for(graphql.schema.GraphQLArgument argument : definition.getArguments()){ GraphQLArgument graphQLArgument = getArgument(argument); subscription.getArguments().add(graphQLArgument); } GraphQLResult result = getResult(definition.getType()); subscription.setResult(result); return subscription; }
public static GraphQLMutation mutation(GraphQLFieldDefinition definition){ final String id = generateId(); final GraphQLMutation mutation = new GraphQLMutation(); mutation.setId(id); mutation.setName(definition.getName()); mutation.setDescription(definition.getDescription()); mutation.setResponseStrategy(GraphQLResponseStrategy.RANDOM); mutation.setStatus(GraphQLOperationStatus.MOCKED); for(graphql.schema.GraphQLArgument argument : definition.getArguments()){ GraphQLArgument graphQLArgument = getArgument(argument); mutation.getArguments().add(graphQLArgument); } GraphQLResult result = getResult(definition.getType()); mutation.setResult(result); return mutation; }
public static GraphQLQuery query(GraphQLFieldDefinition definition){ final String id = generateId(); final GraphQLQuery query = new GraphQLQuery(); query.setId(id); query.setName(definition.getName()); query.setDescription(definition.getDescription()); query.setResponseStrategy(GraphQLResponseStrategy.RANDOM); query.setStatus(GraphQLOperationStatus.MOCKED); for(graphql.schema.GraphQLArgument argument : definition.getArguments()){ GraphQLArgument graphQLArgument = getArgument(argument); query.getArguments().add(graphQLArgument); } GraphQLResult result = getResult(definition.getType()); query.setResult(result); return query; }
public static Builder notNull (Builder aSource) { GraphQLFieldDefinition field = aSource.build(); return create(field.getName()).argument(field.getArguments()) .type(new GraphQLNonNull(field.getType())) .dataFetcher(field.getDataFetcher()) .definition(field.getDefinition()) .deprecate(field.getDeprecationReason()) .description(field.getDescription()); }
@SuppressWarnings("unchecked") @Test public void testDocumentedControllerAndMethods() { GraphQLSchema schema = GraphQLSchemaBuilder.newBuilder() .registerTypeFactory(new JacksonTypeFactory(new ObjectMapper())) .registerGraphQLControllerObjects(ImmutableList.<Object>of(new DocumentedMethodsTest())) .build(); GraphQLObjectType mutationType = (GraphQLObjectType) schema.getMutationType().getFieldDefinition("Mutations").getType(); GraphQLObjectType queryType = (GraphQLObjectType) schema.getQueryType().getFieldDefinition("Queries").getType();; assertEquals("Mutation Description", mutationType.getDescription()); assertEquals("Query Description", queryType.getDescription()); GraphQLFieldDefinition someQuery = queryType.getFieldDefinition("getSomeStrings"); GraphQLFieldDefinition someMutation = mutationType.getFieldDefinition("setSomeStrings"); assertEquals("getSomeStrings description", someQuery.getDescription()); assertEquals("setSomeStrings description", someMutation.getDescription()); } }
private static GraphQLAttribute getAttribute(final GraphQLFieldDefinition definition){ final graphql.schema.GraphQLType type = definition.getType(); final boolean nullable = isNullable(type); final boolean listable = isListable(type); final graphql.schema.GraphQLType coreType = getType(definition.getType()); final String id = generateId(); final GraphQLAttribute attribute = new GraphQLAttribute(); final GraphQLAttributeType attributeType = getAttributeType(coreType); attribute.setName(definition.getName()); attribute.setId(id); attribute.setDescription(definition.getDescription()); attribute.setNullable(nullable); attribute.setListable(listable); attribute.setAttributeType(attributeType); for(graphql.schema.GraphQLArgument argument : definition.getArguments()){ GraphQLArgument graphQLArgument = getArgument(argument); attribute.getArguments().add(graphQLArgument); } if(GraphQLAttributeType.OBJECT_TYPE.equals(attributeType)){ attribute.setTypeName(coreType.getName()); } else if(GraphQLAttributeType.ENUM.equals(attributeType)){ attribute.setTypeName(coreType.getName()); } return attribute; }