public Builder(GraphQLObjectType existing) { name = existing.getName(); description = existing.getDescription(); definition = existing.getDefinition(); fields.putAll(getByName(existing.getFieldDefinitions(), GraphQLFieldDefinition::getName)); interfaces.putAll(getByName(existing.getInterfaces(), GraphQLType::getName)); directives.putAll(getByName(existing.getDirectives(), GraphQLDirective::getName)); }
public GraphQLObjectTypeWrapper(Class<?> objectClass, GraphQLObjectType objectType) { super(objectType.getName(), objectType.getDescription(), objectType.getFieldDefinitions(), objectType.getInterfaces()); this.objectClass = objectClass; }
public Builder(GraphQLObjectType existing) { name = existing.getName(); description = existing.getDescription(); definition = existing.getDefinition(); fields.putAll(getByName(existing.getFieldDefinitions(), GraphQLFieldDefinition::getName)); interfaces.putAll(getByName(existing.getInterfaces(), GraphQLType::getName)); directives.putAll(getByName(existing.getDirectives(), GraphQLDirective::getName)); }
@Test public void metainformation() { GraphQLObjectType object = GraphQLAnnotations.object(TestObject.class); assertEquals(object.getName(), "TestObject"); assertEquals(object.getDescription(), "TestObject object"); }
@Test public void defaults() { GraphQLObjectType object = GraphQLAnnotations.object(TestDefaults.class); assertEquals(object.getName(), "TestDefaults"); assertNull(object.getDescription()); }
@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())); }
private static GraphQLObjectType getObjectType(final graphql.schema.GraphQLObjectType type){ final String name = type.getName(); if(REFUSED_OBJECT_TYPES.contains(name)){ return null; } final String id = generateId(); final GraphQLObjectType graphQLObjectType = new GraphQLObjectType(); graphQLObjectType.setName(name); graphQLObjectType.setId(id); graphQLObjectType.setDescription(type.getDescription()); for(GraphQLFieldDefinition definition : type.getFieldDefinitions()){ GraphQLAttribute attribute = getAttribute(definition); graphQLObjectType.getAttributes().add(attribute); } return graphQLObjectType; }
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()); }
@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()); } }