本文整理汇总了Java中graphql.schema.GraphQLArgument类的典型用法代码示例。如果您正苦于以下问题:Java GraphQLArgument类的具体用法?Java GraphQLArgument怎么用?Java GraphQLArgument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GraphQLArgument类属于graphql.schema包,在下文中一共展示了GraphQLArgument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildValidArgs
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
private void buildValidArgs(boolean isListFetcher) {
validArgs = new LinkedList<GraphQLArgument>();
validArgs.addAll(arguments.values());
//Only accept the f argument if we can actually do anything with it.
if (fetchers.size() > 0) {
String enumName = resource.getBeanClass().getSimpleName() + (isListFetcher ? "s" : "") + "_functions";
GraphQLEnumType.Builder functionNamesEnum = GraphQLEnumType.newEnum()
.name(enumName);
for (String functionName : fetchers.keySet()) {
functionNamesEnum.value(functionName);
}
validArgs.add(GraphQLArgument.newArgument()
.name("f")
.type(functionNamesEnum.build())
.build());
}
}
示例2: testMethodParameterRequired
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
@SuppressWarnings("serial")
@Test
public void testMethodParameterRequired() {
IGraphQLObjectMapper graphQLObjectMapper = newGraphQLObjectMapper(
ImmutableList.<IGraphQLTypeMapper>builder().add(new TestTypeMapper()).addAll(GraphQLSchemaBuilder.getDefaultTypeMappers()).build());
GraphQLObjectType objectType = (GraphQLObjectType) graphQLObjectMapper.getOutputType(new TypeToken<MethodRequiredFields>() {
}.getType());
assertEquals(MethodRequiredFields.class.getSimpleName(), objectType.getName());
assertEquals(1, objectType.getFieldDefinitions().size());
assertNotNull(objectType.getFieldDefinition("method"));
List<GraphQLArgument> arguments = objectType.getFieldDefinition("method").getArguments();
assertEquals(2, arguments.size());
assertEquals(new GraphQLNonNull(Scalars.GraphQLString), arguments.get(0).getType());
assertEquals(Scalars.GraphQLString, arguments.get(1).getType());
}
示例3: getArguments
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
@Override
public List<GraphQLArgument> getArguments(Object object) {
List<GraphQLArgument> arguments = new ArrayList<GraphQLArgument>();
List<ArgContainer> argObjects = getArgRepresentativeObjects(object);
if (argObjects == null) {
return arguments;
}
Set<String> argNames = new HashSet<String>();
for (ArgContainer argObject : argObjects) {
GraphQLArgument.Builder argBuilder = getArgument(argObject);
if (argBuilder == null) {
continue;
}
GraphQLArgument arg = argBuilder.build();
if (argNames.contains(arg.getName())) {
continue;
}
argNames.add(arg.getName());
arguments.add(arg);
}
return arguments;
}
示例4: getArgument
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
protected GraphQLArgument.Builder getArgument(ArgContainer argObject) {
String name = getStrategies().getArgumentNameStrategy().getArgumentName(argObject);
GraphQLInputType type = getStrategies().getArgumentTypeStrategy().getArgumentType(argObject);
if (name == null || type == null) {
return null;
}
String description = getStrategies().getArgumentDescriptionStrategy().getArgumentDescription(argObject);
Object defaultValue = getStrategies().getArgumentDefaultValueStrategy().getArgumentDefaultValue(argObject);
GraphQLArgument.Builder builder = GraphQLArgument.newArgument()
.name(name)
.type(type)
.defaultValue(defaultValue)
.description(description);
return builder;
}
示例5: toGraphQLOperation
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
/**
* Maps a single operation to a GraphQL output field (as queries in GraphQL are nothing but fields of the root operation type).
*
* @param operation The operation to map to a GraphQL output field
* @param buildContext The shared context containing all the global information needed for mapping
*
* @return GraphQL output field representing the given operation
*/
public GraphQLFieldDefinition toGraphQLOperation(Operation operation, BuildContext buildContext) {
Set<Type> abstractTypes = new HashSet<>();
GraphQLOutputType type = toGraphQLType(operation.getJavaType(), abstractTypes, buildContext);
GraphQLFieldDefinition.Builder queryBuilder = newFieldDefinition()
.name(operation.getName())
.description(operation.getDescription())
.type(type);
List<GraphQLArgument> arguments = operation.getArguments().stream()
.filter(OperationArgument::isMappable)
.map(argument -> toGraphQLArgument(argument, abstractTypes, buildContext))
.collect(Collectors.toList());
queryBuilder.argument(arguments);
if (type.getName() != null && !type.getName().equals("Connection") && type.getName().endsWith("Connection")) {
if (buildContext.relay.getConnectionFieldArguments().stream()
.anyMatch(connArg -> arguments.stream()
.anyMatch(arg -> arg.getName().equals(connArg.getName()) && !arg.getType().getName().equals(connArg.getType().getName())))) {
throw new TypeMappingException("Operation \"" + operation.getName() + "\" has arguments of types incompatible with the Relay Connection spec");
}
}
ValueMapper valueMapper = buildContext.valueMapperFactory.getValueMapper(abstractTypes, buildContext.globalEnvironment);
queryBuilder.dataFetcher(createResolver(operation, valueMapper, buildContext.globalEnvironment));
return new MappedGraphQLFieldDefinition(queryBuilder.build(), operation);
}
示例6: call
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
@Override
public List<GraphQLArgument> call(@Nullable Field field, Method method, Class declaringClass, Annotation annotation) {
// if same annotation is detected on both field and getter we fail. Only one annotation is allowed. We can talk about having precedence logic later.
if (method.isAnnotationPresent(annotation.annotationType()) && field != null && field.isAnnotationPresent(annotation.annotationType())) {
throw new IllegalArgumentException("Conflict: GraphQL Annotations can't be added to both field and getter. Pick one for "+
annotation.annotationType() + " on " + field.getName() + " and " + method.getName());
}
Type returnType = GenericTypeReflector.getExactReturnType(method, declaringClass);
if (returnType instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) returnType;
Type containerType = parameterizedType.getRawType();
if (Collection.class.isAssignableFrom((Class) containerType)) {
List<GraphQLArgument> arguments = new ArrayList<>();
arguments.add(newArgument().name(GlitrForwardPagingArguments.FIRST).type(GraphQLInt).build());
arguments.add(newArgument().name(GlitrForwardPagingArguments.AFTER).type(GraphQLString).build());
return arguments;
}
}
return new ArrayList<>();
}
示例7: buildInputObjectArgument
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
/**
* Wraps a constructed GraphQL Input Object in an argument.
* @param entityClass - The class to construct the input object from.
* @param asList Whether or not the argument is a single instance or a list.
* @return The constructed argument.
*/
private GraphQLArgument buildInputObjectArgument(Class<?> entityClass, boolean asList) {
GraphQLInputType argumentType = inputObjectRegistry.get(entityClass);
if (asList) {
return newArgument()
.name(ARGUMENT_DATA)
.type(new GraphQLList(argumentType))
.build();
} else {
return newArgument()
.name(ARGUMENT_DATA)
.type(argumentType)
.build();
}
}
示例8: test_helloWorld
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
@Test
public void test_helloWorld(TestContext context) {
Async async = context.async();
GraphQLObjectType query = GraphQLObjectType.newObject()
.name("query")
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("hello")
.type(Scalars.GraphQLString)
.argument(GraphQLArgument.newArgument().name("myparam").type(Scalars.GraphQLString).build())
.dataFetcher(environment -> {
return environment.getArgument("myparam");
}))
.build();
GraphQLSchema schema = GraphQLSchema.newSchema()
.query(query)
.build();
AsyncGraphQLExec asyncGraphQL = AsyncGraphQLExec.create(schema);
Map<String, Object> params = new HashMap<>();
params.put("p", "myvalue");
Future<JsonObject> queryResult = asyncGraphQL.executeQuery("query ($p: String) { hello(myparam: $p) }", null, null, params);
queryResult.setHandler(res -> {
JsonObject json = res.result();
context.assertEquals(new JsonObject().put("hello", "myvalue"), json);
async.complete();
});
}
示例9: inputConverterShouldCreateArgument
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
@Test
public void inputConverterShouldCreateArgument() {
GqlInputConverter inputConverter =
GqlInputConverter.newBuilder().add(TestProto.getDescriptor().getFile()).build();
GraphQLArgument argument = inputConverter.createArgument(Proto1.getDescriptor(), "input");
Truth.assertThat(argument.getName()).isEqualTo("input");
Truth.assertThat(argument.getType().getName())
.isEqualTo("Input_javatests_com_google_api_graphql_rejoiner_proto_Proto1");
}
示例10: inputConverterShouldCreateArgumentForMessagesInSameFile
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
@Test
public void inputConverterShouldCreateArgumentForMessagesInSameFile() {
GqlInputConverter inputConverter =
GqlInputConverter.newBuilder().add(TestProto.getDescriptor().getFile()).build();
GraphQLArgument argument = inputConverter.createArgument(Proto2.getDescriptor(), "input");
Truth.assertThat(argument.getName()).isEqualTo("input");
Truth.assertThat(argument.getType().getName())
.isEqualTo("Input_javatests_com_google_api_graphql_rejoiner_proto_Proto2");
}
示例11: getQueryType
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
@Bean
@Qualifier("QueryType")
public GraphQLObjectType getQueryType() {
return newObject()
.name("QueryType")
.field(newFieldDefinition()
.name("users")
.type(list(getUserType()))
.dataFetcher(new UserListFetcher(userAdaptor))
.build())
.field(newFieldDefinition()
.name("products")
.type(list(getProductType()))
.dataFetcher(new ProductListFetcher(productAdaptor))
.build())
.field(newFieldDefinition()
.name("orders")
.type(list(getOrderType()))
.dataFetcher(new OrderListFetcher(orderAdaptor))
.build())
.field(newFieldDefinition()
.name("user")
.argument(GraphQLArgument.newArgument()
.name("userId")
.type(GraphQLString)
.build())
.type(getUserType())
.dataFetcher(new UserFetcher(userAdaptor))
.build())
.field(newFieldDefinition()
.name("product")
.argument(GraphQLArgument.newArgument()
.name("productId")
.type(GraphQLString)
.build())
.type(getProductType())
.dataFetcher(new ProductFetcher(productAdaptor))
.build())
.build();
}
示例12: getMutationType
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
@Bean
@Qualifier("MutationType")
public GraphQLObjectType getMutationType() {
return newObject()
.name("MutationType")
.field(newFieldDefinition()
.name("createProduct")
.type(productType)
.argument(GraphQLArgument.newArgument()
.name("name")
.type(GraphQLString)
.build())
.argument(GraphQLArgument.newArgument()
.name("price")
.type(GraphQLFloat)
.build())
.dataFetcher(new ProductUpsertFetcher(productAdaptor))
.build())
.field(newFieldDefinition()
.name("createProductObject")
.type(productType)
.argument(GraphQLArgument.newArgument()
.name("product")
.type(getInputProductType())
.build())
.dataFetcher(new ProductUpsertFetcher(productAdaptor))
.build())
.field(newFieldDefinition()
.name("deleteProduct")
.type(productType)
.argument(GraphQLArgument.newArgument()
.name("productId")
.type(GraphQLID)
.build())
.dataFetcher(new ProductDeleteFetcher(productAdaptor))
.build())
.build();
}
示例13: getFieldFetcher
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
@Override
public Object getFieldFetcher(Object object) {
Object fetcher = getNextStrategy().getFieldFetcher(object);
if (!(fetcher instanceof ArgAwareDataFetcher)) {
return fetcher;
}
List<GraphQLArgument> arguments = getContext()
.getArgumentsGeneratorStrategy().getArguments(object);
if (arguments == null || arguments.isEmpty()) {
return fetcher;
}
return new GraphQLInputAwareDataFetcher(
new ArgumentExtractingDataFetcher((ArgAwareDataFetcher) fetcher), arguments);
}
开发者ID:graphql-java,项目名称:graphql-java-type-generator,代码行数:16,代码来源:FieldDataFetcher_InputAndArgAware.java
示例14: getFieldFetcherFromMethod
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
protected Object getFieldFetcherFromMethod(Method method, Object methodSource) {
MethodInvokingDataFetcher methodInvoker = new MethodInvokingDataFetcher(method);
methodInvoker.setSource(methodSource);
List<GraphQLArgument> arguments = getContext()
.getArgumentsGeneratorStrategy().getArguments(method);
if (arguments == null || arguments.isEmpty()) {
return methodInvoker;
}
return new GraphQLInputAwareDataFetcher(
new ArgumentExtractingDataFetcher(methodInvoker), arguments);
}
示例15: getOutputFieldDefinition
import graphql.schema.GraphQLArgument; //导入依赖的package包/类
/**
* May return null should this field be disallowed
* @param object
* @return
*/
protected GraphQLFieldDefinition.Builder getOutputFieldDefinition(
final Object object) {
String fieldName = getFieldName(object);
GraphQLOutputType fieldType = (GraphQLOutputType)
getTypeOfField(object, TypeKind.OBJECT);
if (fieldName == null || fieldType == null) {
return null;
}
Object fieldFetcher = getFieldFetcher(object);
String fieldDescription = getFieldDescription(object);
String fieldDeprecation = getFieldDeprecation(object);
List<GraphQLArgument> fieldArguments = getFieldArguments(object);
logger.debug("GraphQL field will be of type [{}] and name [{}] and fetcher [{}] with description [{}]",
fieldType, fieldName, fieldFetcher, fieldDescription);
GraphQLFieldDefinition.Builder fieldBuilder = newFieldDefinition()
.name(fieldName)
.type(fieldType)
.description(fieldDescription)
.deprecate(fieldDeprecation);
if (fieldArguments != null) {
fieldBuilder.argument(fieldArguments);
}
if (fieldFetcher instanceof DataFetcher) {
fieldBuilder.dataFetcher((DataFetcher)fieldFetcher);
}
else if (fieldFetcher != null) {
fieldBuilder.staticValue(fieldFetcher);
}
return fieldBuilder;
}