/** * This will decorate a graphql type with the original hierarchy of non null and list'ness * it originally contained in its definition type * * @param objectType this should be a graphql type that was originally built from this raw type * @param <T> the type * * @return the decorated type */ @SuppressWarnings("TypeParameterUnusedInFormals") public <T extends GraphQLType> T decorate(GraphQLType objectType) { GraphQLType out = objectType; Stack<Class<?>> wrappingStack = new Stack<>(); wrappingStack.addAll(this.decoration); while (!wrappingStack.isEmpty()) { Class<?> clazz = wrappingStack.pop(); if (clazz.equals(NonNullType.class)) { out = nonNull(out); } if (clazz.equals(ListType.class)) { out = list(out); } } // we handle both input and output graphql types //noinspection unchecked return (T) out; }
/** * We support the basic types as directive types * * @param value the value to use * * @return a graphql input type */ public GraphQLInputType buildDirectiveInputType(Value value) { if (value instanceof NullValue) { return Scalars.GraphQLString; } if (value instanceof FloatValue) { return Scalars.GraphQLFloat; } if (value instanceof StringValue) { return Scalars.GraphQLString; } if (value instanceof IntValue) { return Scalars.GraphQLInt; } if (value instanceof BooleanValue) { return Scalars.GraphQLBoolean; } if (value instanceof ArrayValue) { ArrayValue arrayValue = (ArrayValue) value; return list(buildDirectiveInputType(getArrayValueWrappedType(arrayValue))); } return assertShouldNeverHappen("Directive values of type '%s' are not supported yet", value.getClass().getSimpleName()); }
public static GraphQLType getTypeFromAST(GraphQLSchema schema, Type type) { GraphQLType innerType; if (type instanceof ListType) { innerType = getTypeFromAST(schema, ((ListType) type).getType()); return innerType != null ? list(innerType) : null; } else if (type instanceof NonNullType) { innerType = getTypeFromAST(schema, ((NonNullType) type).getType()); return innerType != null ? nonNull(innerType) : null; } return schema.getType(((TypeName) type).getName()); } }
void recursiveTypes() { GraphQLObjectType person = newObject() .name("Person") .field(newFieldDefinition() .name("friends") .type(GraphQLList.list(GraphQLTypeReference.typeRef("Person")))) .build(); }
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(); }
.field(newFieldDefinition() .name("anyIterable") .type(list(GraphQLString)) .dataFetcher(anyIterableFetcher)) .field(newFieldDefinition() .name("shatter") .type(nonNull(list(nonNull(typeRef("StringObject"))))) .dataFetcher(shatterFetcher)) .type(nonNull(list(nonNull(list(nonNull(typeRef("StringObject"))))))) .dataFetcher(wordsAndLettersFetcher)) .name("split") .description("String#split(regex) but replace empty strings with nulls to help us test null behavior in lists") .type(list(typeRef("StringObject"))) .argument(GraphQLArgument.newArgument() .name("regex") .name("splitNotNull") .description("String#split(regex) but replace empty strings with nulls to help us test null behavior in lists") .type(list(nonNull(typeRef("StringObject")))) .argument(GraphQLArgument.newArgument() .name("regex")
/** * This will decorate a graphql type with the original hierarchy of non null and list'ness * it originally contained in its definition type * * @param objectType this should be a graphql type that was originally built from this raw type * @param <T> the type * * @return the decorated type */ @SuppressWarnings("TypeParameterUnusedInFormals") public <T extends GraphQLType> T decorate(GraphQLType objectType) { GraphQLType out = objectType; Stack<Class<?>> wrappingStack = new Stack<>(); wrappingStack.addAll(this.decoration); while (!wrappingStack.isEmpty()) { Class<?> clazz = wrappingStack.pop(); if (clazz.equals(NonNullType.class)) { out = nonNull(out); } if (clazz.equals(ListType.class)) { out = list(out); } } // we handle both input and output graphql types //noinspection unchecked return (T) out; }
/** * We support the basic types as directive types * * @param value the value to use * * @return a graphql input type */ public GraphQLInputType buildDirectiveInputType(Value value) { if (value instanceof NullValue) { return Scalars.GraphQLString; } if (value instanceof FloatValue) { return Scalars.GraphQLFloat; } if (value instanceof StringValue) { return Scalars.GraphQLString; } if (value instanceof IntValue) { return Scalars.GraphQLInt; } if (value instanceof BooleanValue) { return Scalars.GraphQLBoolean; } if (value instanceof ArrayValue) { ArrayValue arrayValue = (ArrayValue) value; return list(buildDirectiveInputType(getArrayValueWrappedType(arrayValue))); } return assertShouldNeverHappen("Directive values of type '%s' are not supported yet", value.getClass().getSimpleName()); }
public static GraphQLType getTypeFromAST(GraphQLSchema schema, Type type) { GraphQLType innerType; if (type instanceof ListType) { innerType = getTypeFromAST(schema, ((ListType) type).getType()); return innerType != null ? list(innerType) : null; } else if (type instanceof NonNullType) { innerType = getTypeFromAST(schema, ((NonNullType) type).getType()); return innerType != null ? nonNull(innerType) : null; } return schema.getType(((TypeName) type).getName()); } }
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(); }
GraphQLOutputType type = GraphQLList.list(fieldListBuilder.build());