graphql.schema.GraphQLArgument Java Examples
The following examples show how to use
graphql.schema.GraphQLArgument.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OperationMapper.java From graphql-spqr with Apache License 2.0 | 6 votes |
private GraphQLFieldDefinition toGraphQLField(Operation operation, BuildContext buildContext) { GraphQLOutputType type = toGraphQLType(operation.getJavaType(), new TypeMappingEnvironment(operation.getTypedElement(), this, buildContext)); GraphQLFieldDefinition.Builder fieldBuilder = newFieldDefinition() .name(operation.getName()) .description(operation.getDescription()) .deprecate(operation.getDeprecationReason()) .type(type) .withDirective(Directives.mappedOperation(operation)) .withDirectives(toGraphQLDirectives(operation.getTypedElement(), buildContext.directiveBuilder::buildFieldDefinitionDirectives, buildContext)); List<GraphQLArgument> arguments = operation.getArguments().stream() .filter(OperationArgument::isMappable) .map(argument -> toGraphQLArgument(argument, buildContext)) .collect(Collectors.toList()); fieldBuilder.arguments(arguments); if (GraphQLUtils.isRelayConnectionType(type) && buildContext.relayMappingConfig.strictConnectionSpec) { validateConnectionSpecCompliance(operation.getName(), arguments, buildContext.relay); } return buildContext.transformers.transform(fieldBuilder.build(), operation, this, buildContext); }
Example #2
Source File: HGQLSchemaWiring.java From hypergraphql with Apache License 2.0 | 6 votes |
private GraphQLFieldDefinition getBuiltField(FieldOfTypeConfig field, DataFetcher fetcher) { List<GraphQLArgument> args = new ArrayList<>(); if (field.getTargetName().equals("String")) { args.add(defaultArguments.get("lang")); } if(field.getService() == null) { throw new HGQLConfigurationException("Value of 'service' for field '" + field.getName() + "' cannot be null"); } String description = field.getId() + " (source: " + field.getService().getId() + ")."; return newFieldDefinition() .name(field.getName()) .argument(args) .description(description) .type(field.getGraphqlOutputType()) .dataFetcher(fetcher) .build(); }
Example #3
Source File: ArgumentsGenerator.java From graphql-java-type-generator with MIT License | 6 votes |
@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; }
Example #4
Source File: ArgumentsGenerator.java From graphql-java-type-generator with MIT License | 6 votes |
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; }
Example #5
Source File: CustomFieldArgumentsFunc.java From glitr with MIT License | 6 votes |
@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<>(); }
Example #6
Source File: SchemaModuleTest.java From rejoiner with Apache License 2.0 | 6 votes |
@Test public void schemaModuleShouldApplyProtoEnumArgs() { Injector injector = Guice.createInjector( new SchemaModule() { @Mutation("mutationMethodWithArgs") ListenableFuture<GreetingsResponse> mutationMethod( GreetingsRequest request, @Arg("myLanguage") Greetings.Languages myLanguage) { return Futures.immediateFuture( GreetingsResponse.newBuilder().setId(request.getId()).build()); } }); SchemaBundle schemaBundle = SchemaBundle.combine(injector.getInstance(KEY)); assertThat(schemaBundle.mutationFields()).hasSize(1); List<GraphQLArgument> arguments = schemaBundle.mutationFields().get(0).getArguments(); assertThat(arguments).hasSize(2); assertThat( arguments.stream() .map(argument -> argument.getName()) .collect(ImmutableList.toImmutableList())) .containsExactly("input", "myLanguage"); }
Example #7
Source File: HGQLSchemaWiring.java From hypergraphql with Apache License 2.0 | 6 votes |
private GraphQLFieldDefinition getBuiltField(FieldOfTypeConfig field, DataFetcher fetcher) { List<GraphQLArgument> args = new ArrayList<>(); if (field.getTargetName().equals("String")) { args.add(defaultArguments.get("lang")); } if(field.getService() == null) { throw new HGQLConfigurationException("Value of 'service' for field '" + field.getName() + "' cannot be null"); } String description = field.getId() + " (source: " + field.getService().getId() + ")."; return newFieldDefinition() .name(field.getName()) .argument(args) .description(description) .type(field.getGraphqlOutputType()) .dataFetcher(fetcher) .build(); }
Example #8
Source File: OperationMapper.java From graphql-spqr with Apache License 2.0 | 6 votes |
private void validateConnectionSpecCompliance(String operationName, List<GraphQLArgument> arguments, Relay relay) { String errorMessageTemplate = "Operation '" + operationName + "' is incompatible with the Relay Connection spec due to %s. " + "If this is intentional, disable strict compliance checking. " + "For details and solutions see " + Urls.Errors.RELAY_CONNECTION_SPEC_VIOLATION; boolean forwardPageSupported = relay.getForwardPaginationConnectionFieldArguments().stream().allMatch( specArg -> arguments.stream().anyMatch(arg -> arg.getName().equals(specArg.getName()))); boolean backwardPageSupported = relay.getBackwardPaginationConnectionFieldArguments().stream().allMatch( specArg -> arguments.stream().anyMatch(arg -> arg.getName().equals(specArg.getName()))); if (!forwardPageSupported && !backwardPageSupported) { throw new MappingException(String.format(errorMessageTemplate, "required arguments missing")); } if (relay.getConnectionFieldArguments().stream().anyMatch(specArg -> arguments.stream().anyMatch( arg -> arg.getName().equals(specArg.getName()) && !GraphQLUtils.unwrap(arg.getType()).getName().equals(name(specArg.getType()))))) { throw new MappingException(String.format(errorMessageTemplate, "argument type mismatch")); } }
Example #9
Source File: GraphQLSchemaGenerator.java From graphql-spqr with Apache License 2.0 | 5 votes |
private boolean isRealType(GraphQLNamedType type) { // Reject introspection types return !(GraphQLUtils.isIntrospectionType(type) // Reject quasi-types || type instanceof GraphQLTypeReference || type instanceof GraphQLArgument || type instanceof GraphQLDirective // Reject root types || type.getName().equals(messageBundle.interpolate(queryRoot)) || type.getName().equals(messageBundle.interpolate(mutationRoot)) || type.getName().equals(messageBundle.interpolate(subscriptionRoot))); }
Example #10
Source File: DefaultTypeInfoGenerator.java From graphql-spqr with Apache License 2.0 | 5 votes |
@Override public <T extends GraphQLSchemaElement> Comparator<? super T> getComparator(GraphqlTypeComparatorEnvironment env) { //Leave the arguments in the declared order if (env.getElementType().equals(GraphQLArgument.class)) { return GraphqlTypeComparatorRegistry.AS_IS_REGISTRY.getComparator(env); } //Sort everything else by name return GraphqlTypeComparatorRegistry.BY_NAME_REGISTRY.getComparator(env); }
Example #11
Source File: Directives.java From graphql-spqr with Apache License 2.0 | 5 votes |
public static GraphQLDirective mappedType(AnnotatedType type) { return GraphQLDirective.newDirective() .name(MAPPED_TYPE) .description("") .validLocation(Introspection.DirectiveLocation.OBJECT) .argument(GraphQLArgument.newArgument() .name(TYPE) .description("") .value(type) .type(UNREPRESENTABLE) .build()) .build(); }
Example #12
Source File: Directives.java From graphql-spqr with Apache License 2.0 | 5 votes |
public static GraphQLDirective mappedOperation(Operation operation) { return GraphQLDirective.newDirective() .name(MAPPED_OPERATION) .description("") .validLocation(Introspection.DirectiveLocation.FIELD_DEFINITION) .argument(GraphQLArgument.newArgument() .name(OPERATION) .description("") .value(operation) .type(UNREPRESENTABLE) .build()) .build(); }
Example #13
Source File: OperationMapper.java From graphql-spqr with Apache License 2.0 | 5 votes |
private GraphQLArgument toGraphQLArgument(DirectiveArgument directiveArgument, BuildContext buildContext) { GraphQLArgument argument = newArgument() .name(directiveArgument.getName()) .description(directiveArgument.getDescription()) .type(toGraphQLInputType(directiveArgument.getJavaType(), new TypeMappingEnvironment(directiveArgument.getTypedElement(), this, buildContext))) .value(directiveArgument.getValue()) .defaultValue(directiveArgument.getDefaultValue()) .withDirectives(toGraphQLDirectives(directiveArgument.getTypedElement(), buildContext.directiveBuilder::buildArgumentDefinitionDirectives, buildContext)) .build(); return buildContext.transformers.transform(argument, directiveArgument, this, buildContext); }
Example #14
Source File: Directives.java From graphql-spqr with Apache License 2.0 | 5 votes |
public static GraphQLDirective mappedInputField(InputField inputField) { return GraphQLDirective.newDirective() .name(MAPPED_INPUT_FIELD) .description("") .validLocation(Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION) .argument(GraphQLArgument.newArgument() .name(INPUT_FIELD) .description("") .value(inputField) .type(UNREPRESENTABLE) .build()) .build(); }
Example #15
Source File: OperationMapper.java From graphql-spqr with Apache License 2.0 | 5 votes |
private GraphQLArgument toGraphQLArgument(OperationArgument operationArgument, BuildContext buildContext) { GraphQLArgument argument = newArgument() .name(operationArgument.getName()) .description(operationArgument.getDescription()) .type(toGraphQLInputType(operationArgument.getJavaType(), new TypeMappingEnvironment(operationArgument.getTypedElement(), this, buildContext))) .defaultValue(operationArgument.getDefaultValue()) .withDirectives(toGraphQLDirectives(operationArgument.getTypedElement(), buildContext.directiveBuilder::buildArgumentDefinitionDirectives, buildContext)) .build(); return buildContext.transformers.transform(argument, operationArgument, this, buildContext); }
Example #16
Source File: FieldsGenerator.java From graphql-java-type-generator with MIT License | 5 votes |
/** * 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; }
Example #17
Source File: FieldDataFetcher_Reflection.java From graphql-java-type-generator with MIT License | 5 votes |
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); }
Example #18
Source File: FieldDataFetcher_InputAndArgAware.java From graphql-java-type-generator with MIT License | 5 votes |
@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); }
Example #19
Source File: UniquenessTest.java From graphql-spqr with Apache License 2.0 | 5 votes |
private void testRootQueryArgumentTypeUniqueness(GraphQLSchema schema) { List<GraphQLType> inputTypes = schema.getQueryType().getFieldDefinitions().stream() .flatMap(def -> def.getArguments().stream()) .map(GraphQLArgument::getType) .map(GraphQLUtils::unwrap) .collect(Collectors.toList()); assertEquals(2, inputTypes.size()); assertTrue(inputTypes.stream().allMatch(type -> inputTypes.get(0) == type)); }
Example #20
Source File: NonNullMapper.java From graphql-spqr with Apache License 2.0 | 5 votes |
@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); }
Example #21
Source File: NonNullMapper.java From graphql-spqr with Apache License 2.0 | 5 votes |
private GraphQLArgument transformArgument(GraphQLArgument argument, TypedElement element, String description, OperationMapper operationMapper, BuildContext buildContext) { if (argument.getDefaultValue() == null && shouldWrap(argument.getType(), element)) { return argument.transform(builder -> builder.type(new GraphQLNonNull(argument.getType()))); } if (shouldUnwrap(argument.getDefaultValue(), argument.getType())) { //do not warn on primitives as their non-nullness is implicit if (!ClassUtils.getRawType(element.getJavaType().getType()).isPrimitive()) { log.warn("Non-null argument with a default value will be treated as nullable: " + description); } return argument.transform(builder -> builder.type((GraphQLInputType) GraphQLUtils.unwrapNonNull(argument.getType()))); } return argument; }
Example #22
Source File: HGQLSchemaWiring.java From hypergraphql with Apache License 2.0 | 5 votes |
private GraphQLFieldDefinition getBuiltQueryField(FieldOfTypeConfig field, DataFetcher fetcher) { List<GraphQLArgument> args = new ArrayList<>(); if (this.hgqlSchema.getQueryFields().get(field.getName()).type().equals(HGQL_QUERY_GET_FIELD)) { args.addAll(getQueryArgs); } else { args.addAll(getByIdQueryArgs); } final QueryFieldConfig queryFieldConfig = this.hgqlSchema.getQueryFields().get(field.getName()); Service service = queryFieldConfig.service(); if(service == null) { throw new HGQLConfigurationException("Service for field '" + queryFieldConfig.type() + "' not specified (null)"); } String serviceId = service.getId(); String description = (queryFieldConfig.type().equals(HGQL_QUERY_GET_FIELD)) ? "Get instances of " + field.getTargetName() + " (service: " + serviceId + ")" : "Get instances of " + field.getTargetName() + " by URIs (service: " + serviceId + ")"; return newFieldDefinition() .name(field.getName()) .argument(args) .description(description) .type(field.getGraphqlOutputType()) .dataFetcher(fetcher) .build(); }
Example #23
Source File: ManualGraphQLMutationSchema.java From research-graphql with MIT License | 5 votes |
@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(); }
Example #24
Source File: DefaultValueSchemaTransformer.java From graphql-spqr-spring-boot-starter with Apache License 2.0 | 5 votes |
@Override default GraphQLArgument transformArgument(GraphQLArgument argument, OperationArgument operationArgument, OperationMapper operationMapper, BuildContext buildContext) { if (supports(operationArgument.getJavaType()) && !(argument.getType() instanceof GraphQLNonNull) && argument.getDefaultValue() == null) { return argument.transform(builder -> builder.defaultValue(getDefaultValue())); } return argument; }
Example #25
Source File: GraphQLSchemaBuilder.java From graphql-jpa with MIT License | 5 votes |
private Stream<GraphQLArgument> getArgument(Attribute attribute) { return getAttributeType(attribute) .filter(type -> type instanceof GraphQLInputType) .filter(type -> attribute.getPersistentAttributeType() != Attribute.PersistentAttributeType.EMBEDDED || (attribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.EMBEDDED && type instanceof GraphQLScalarType)) .map(type -> { String name = attribute.getName(); return GraphQLArgument.newArgument() .name(name) .type((GraphQLInputType) type) .build(); }); }
Example #26
Source File: GraphQLDocumentationProvider.java From js-graphql-intellij-plugin with MIT License | 5 votes |
@NotNull private String getArgumentDocumentation(String inputValueName, GraphQLArgument argument) { final StringBuilder html = new StringBuilder().append(DEFINITION_START); GraphQLInputType argumentType = argument.getType(); html.append(inputValueName).append(argumentType != null ? ": " : " ").append(argumentType != null ? GraphQLUtil.getName(argumentType) : ""); html.append(DEFINITION_END); appendDescription(html, GraphQLDocumentationMarkdownRenderer.getDescriptionAsHTML(argument.getDescription())); return html.toString(); }
Example #27
Source File: FederationSdlPrinter.java From federation-jvm with MIT License | 5 votes |
private String directiveDefinition(GraphQLDirective directive) { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(); printComments(new PrintWriter(sw), directive, ""); sb.append(sw.toString()); sb.append("directive @").append(directive.getName()); GraphqlTypeComparatorEnvironment environment = GraphqlTypeComparatorEnvironment.newEnvironment() .parentType(GraphQLDirective.class) .elementType(GraphQLArgument.class) .build(); Comparator<? super GraphQLSchemaElement> comparator = options.comparatorRegistry.getComparator(environment); List<GraphQLArgument> args = directive.getArguments(); args = args .stream() .sorted(comparator) .collect(toList()); sb.append(argsString(GraphQLDirective.class, args)); sb.append(" on "); String locations = directive.validLocations().stream().map(Enum::name).collect(Collectors.joining(" | ")); sb.append(locations); return sb.toString(); }
Example #28
Source File: Bootstrap.java From smallrye-graphql with Apache License 2.0 | 5 votes |
private GraphQLArgument createGraphQLArgument(Argument argument) { GraphQLArgument.Builder argumentBuilder = GraphQLArgument.newArgument() .name(argument.getName()) .description(argument.getDescription()) .defaultValue(sanitizeDefaultValue(argument)); GraphQLInputType graphQLInputType = referenceGraphQLInputType(argument); // Collection if (argument.hasArray()) { Array array = argument.getArray(); // Mandatory in the collection if (array.isNotEmpty()) { graphQLInputType = GraphQLNonNull.nonNull(graphQLInputType); } // Collection depth for (int i = 0; i < array.getDepth(); i++) { graphQLInputType = GraphQLList.list(graphQLInputType); } } // Mandatory if (argument.isNotNull()) { graphQLInputType = GraphQLNonNull.nonNull(graphQLInputType); } argumentBuilder = argumentBuilder.type(graphQLInputType); return argumentBuilder.build(); }
Example #29
Source File: HGQLSchemaWiring.java From hypergraphql with Apache License 2.0 | 5 votes |
private GraphQLFieldDefinition getBuiltQueryField(FieldOfTypeConfig field, DataFetcher fetcher) { List<GraphQLArgument> args = new ArrayList<>(); if (this.hgqlSchema.getQueryFields().get(field.getName()).type().equals(HGQL_QUERY_GET_FIELD)) { args.addAll(getQueryArgs); } else { args.addAll(getByIdQueryArgs); } final QueryFieldConfig queryFieldConfig = this.hgqlSchema.getQueryFields().get(field.getName()); Service service = queryFieldConfig.service(); if(service == null) { throw new HGQLConfigurationException("Service for field '" + field.getName() + "':['" + queryFieldConfig.type() + "'] not specified (null)"); } String serviceId = service.getId(); String description = (queryFieldConfig.type().equals(HGQL_QUERY_GET_FIELD)) ? "Get instances of " + field.getTargetName() + " (service: " + serviceId + ")" : "Get instances of " + field.getTargetName() + " by URIs (service: " + serviceId + ")"; return newFieldDefinition() .name(field.getName()) .argument(args) .description(description) .type(field.getGraphqlOutputType()) .dataFetcher(fetcher) .build(); }
Example #30
Source File: Arguments.java From spring-boot-starter-graphql with Apache License 2.0 | 5 votes |
public static GraphQLArgument.Builder notNull (GraphQLArgument.Builder aBuilder) { GraphQLArgument arg = aBuilder.build(); return GraphQLArgument.newArgument() .name(arg.getName()) .defaultValue(arg.getDefaultValue()) .definition(arg.getDefinition()) .description(arg.getDescription()) .type(new GraphQLNonNull(arg.getType())); }