本文整理了Java中graphql.schema.GraphQLNonNull.nonNull()
方法的一些代码示例,展示了GraphQLNonNull.nonNull()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GraphQLNonNull.nonNull()
方法的具体详情如下:
包路径:graphql.schema.GraphQLNonNull
类名称:GraphQLNonNull
方法名:nonNull
[英]A factory method for creating non null types so that when used with static imports allows more readable code such as .type(nonNull(GraphQLString))
[中]一种工厂方法,用于创建非空类型,以便在与静态导入一起使用时允许更可读的代码,例如。类型(非空(GraphQLString))
代码示例来源:origin: graphql-java/graphql-java
public GraphQLType effectiveType(GraphQLType variableType, Value defaultValue) {
if (defaultValue == null) {
return variableType;
}
if (isNonNull(variableType)) {
return variableType;
}
return nonNull(variableType);
}
代码示例来源:origin: graphql-java/graphql-java
/**
* 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
*
* @return the decorated type
*/
@SuppressWarnings("TypeParameterUnusedInFormals")
public
GraphQLType out = objectType;
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;
}
代码示例来源:origin: graphql-java/graphql-java
/**
* 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);
}
}
代码示例来源:origin: graphql-java/graphql-java
void listsAndNonNullLists() {
GraphQLList.list(GraphQLString); // a list of Strings
GraphQLNonNull.nonNull(GraphQLString); // a non null String
// with static imports its even shorter
newArgument()
.name("example")
.type(nonNull(list(GraphQLString)));
}
代码示例来源:origin: graphql-java/graphql-java
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());
}
}
代码示例来源:origin: graphql-java/graphql-java
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();
}
代码示例来源:origin: graphql-java/graphql-java
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();
}
代码示例来源:origin: graphql-java/graphql-java
public GraphQLObjectType edgeType(String name, GraphQLOutputType nodeType, GraphQLInterfaceType nodeInterface, List
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();
}
代码示例来源:origin: graphql-java/graphql-java
public GraphQLObjectType connectionType(String name, GraphQLObjectType edgeType, List
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();
}
代码示例来源:origin: graphql-java/graphql-java
public GraphQLFieldDefinition mutation(String name, String fieldName,
List
List
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();
}
代码示例来源:origin: graphql-java/graphql-java
.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")
代码示例来源:origin: com.graphql-java/graphql-java
public GraphQLType effectiveType(GraphQLType variableType, Value defaultValue) {
if (defaultValue == null) {
return variableType;
}
if (isNonNull(variableType)) {
return variableType;
}
return nonNull(variableType);
}
代码示例来源:origin: com.graphql-java/graphql-java
/**
* 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);
}
}
代码示例来源:origin: com.graphql-java/graphql-java
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());
}
}
代码示例来源:origin: leangen/graphql-spqr
@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);
}
代码示例来源:origin: com.graphql-java/graphql-java
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();
}
代码示例来源:origin: com.graphql-java/graphql-java
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();
}
代码示例来源:origin: com.graphql-java/graphql-java
public GraphQLObjectType edgeType(String name, GraphQLOutputType nodeType, GraphQLInterfaceType nodeInterface, List
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();
}
代码示例来源:origin: com.graphql-java/graphql-java
public GraphQLObjectType connectionType(String name, GraphQLObjectType edgeType, List
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();
}
代码示例来源:origin: com.graphql-java/graphql-java
public GraphQLFieldDefinition mutation(String name, String fieldName,
List
List
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();
}