public GraphQLType effectiveType(GraphQLType variableType, Value defaultValue) { if (defaultValue == null) { return variableType; } if (isNonNull(variableType)) { return variableType; } return nonNull(variableType); }
/** * 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; }
/** * This allows you to morph a type into a more specialized form yet return the same * parent and non-null ness, for example taking a {@link GraphQLInterfaceType} * and turning it into a specific {@link graphql.schema.GraphQLObjectType} * after type resolution has occurred * * @param newType the new type to be * * @return a new type info with the same */ public ExecutionStepInfo changeTypeWithPreservedNonNull(GraphQLOutputType newType) { assertTrue(!GraphQLTypeUtil.isNonNull(newType), "newType can't be non null"); if (isNonNullType()) { return new ExecutionStepInfo(GraphQLNonNull.nonNull(newType), fieldDefinition, field, path, this.parent, arguments, this.fieldContainer); } else { return new ExecutionStepInfo(newType, fieldDefinition, field, path, this.parent, arguments, this.fieldContainer); } }
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 GraphQLInterfaceType nodeInterface(TypeResolver typeResolver) { return newInterface() .name(NODE) .description("An object with an ID") .typeResolver(typeResolver) .field(newFieldDefinition() .name("id") .description("The ID of an object") .type(nonNull(GraphQLID))) .build(); }
public GraphQLFieldDefinition nodeField(GraphQLInterfaceType nodeInterface, DataFetcher nodeDataFetcher) { return newFieldDefinition() .name("node") .description("Fetches an object given its ID") .type(nodeInterface) .dataFetcher(nodeDataFetcher) .argument(newArgument() .name("id") .description("The ID of an object") .type(nonNull(GraphQLID))) .build(); }
public GraphQLObjectType edgeType(String name, GraphQLOutputType nodeType, GraphQLInterfaceType nodeInterface, List<GraphQLFieldDefinition> edgeFields) { return newObject() .name(name + "Edge") .description("An edge in a connection") .field(newFieldDefinition() .name("node") .type(nodeType) .description("The item at the end of the edge")) .field(newFieldDefinition() .name("cursor") .type(nonNull(GraphQLString)) .description("cursor marks a unique position or index into the connection")) .fields(edgeFields) .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(); }
public GraphQLFieldDefinition mutation(String name, String fieldName, List<GraphQLInputObjectField> inputFields, List<GraphQLFieldDefinition> outputFields, DataFetcher dataFetcher) { GraphQLInputObjectType inputObjectType = newInputObject() .name(name + "Input") .fields(inputFields) .build(); GraphQLObjectType outputType = newObject() .name(name + "Payload") .fields(outputFields) .build(); return newFieldDefinition() .name(fieldName) .type(outputType) .argument(newArgument() .name("input") .type(nonNull(inputObjectType))) .dataFetcher(dataFetcher) .build(); }
.field(newFieldDefinition() .name("nonNullValue") .type(nonNull(GraphQLString)) .dataFetcher(stringObjectValueFetcher)) .field(newFieldDefinition() .field(newFieldDefinition() .name("shatter") .type(nonNull(list(nonNull(typeRef("StringObject"))))) .dataFetcher(shatterFetcher)) .type(nonNull(list(nonNull(list(nonNull(typeRef("StringObject"))))))) .dataFetcher(wordsAndLettersFetcher)) .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")
public GraphQLType effectiveType(GraphQLType variableType, Value defaultValue) { if (defaultValue == null) { return variableType; } if (isNonNull(variableType)) { return variableType; } return nonNull(variableType); }
/** * This allows you to morph a type into a more specialized form yet return the same * parent and non-null ness, for example taking a {@link GraphQLInterfaceType} * and turning it into a specific {@link graphql.schema.GraphQLObjectType} * after type resolution has occurred * * @param newType the new type to be * * @return a new type info with the same */ public ExecutionStepInfo changeTypeWithPreservedNonNull(GraphQLOutputType newType) { assertTrue(!GraphQLTypeUtil.isNonNull(newType), "newType can't be non null"); if (isNonNullType()) { return new ExecutionStepInfo(GraphQLNonNull.nonNull(newType), fieldDefinition, field, path, this.parent, arguments, this.fieldContainer); } else { return new ExecutionStepInfo(newType, fieldDefinition, field, path, this.parent, arguments, this.fieldContainer); } }
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()); } }
@Override public GraphQLArgument transformArgument(GraphQLArgument argument, DirectiveArgument directiveArgument, OperationMapper operationMapper, BuildContext buildContext) { if (directiveArgument.getAnnotation() != null && directiveArgument.getDefaultValue() == null) { return argument.transform(builder -> builder.type(GraphQLNonNull.nonNull(argument.getType()))); } return transformArgument(argument, directiveArgument.getTypedElement(), directiveArgument.toString(), operationMapper, buildContext); }
public GraphQLInterfaceType nodeInterface(TypeResolver typeResolver) { return newInterface() .name(NODE) .description("An object with an ID") .typeResolver(typeResolver) .field(newFieldDefinition() .name("id") .description("The ID of an object") .type(nonNull(GraphQLID))) .build(); }
public GraphQLFieldDefinition nodeField(GraphQLInterfaceType nodeInterface, DataFetcher nodeDataFetcher) { return newFieldDefinition() .name("node") .description("Fetches an object given its ID") .type(nodeInterface) .dataFetcher(nodeDataFetcher) .argument(newArgument() .name("id") .description("The ID of an object") .type(nonNull(GraphQLID))) .build(); }
public GraphQLObjectType edgeType(String name, GraphQLOutputType nodeType, GraphQLInterfaceType nodeInterface, List<GraphQLFieldDefinition> edgeFields) { return newObject() .name(name + "Edge") .description("An edge in a connection") .field(newFieldDefinition() .name("node") .type(nodeType) .description("The item at the end of the edge")) .field(newFieldDefinition() .name("cursor") .type(nonNull(GraphQLString)) .description("cursor marks a unique position or index into the connection")) .fields(edgeFields) .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(); }
public GraphQLFieldDefinition mutation(String name, String fieldName, List<GraphQLInputObjectField> inputFields, List<GraphQLFieldDefinition> outputFields, DataFetcher dataFetcher) { GraphQLInputObjectType inputObjectType = newInputObject() .name(name + "Input") .fields(inputFields) .build(); GraphQLObjectType outputType = newObject() .name(name + "Payload") .fields(outputFields) .build(); return newFieldDefinition() .name(fieldName) .type(outputType) .argument(newArgument() .name("input") .type(nonNull(inputObjectType))) .dataFetcher(dataFetcher) .build(); }