Java Code Examples for graphql.language.OperationDefinition#Operation

The following examples show how to use graphql.language.OperationDefinition#Operation . 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: GqlParentType.java    From manifold with Apache License 2.0 6 votes vote down vote up
private TypeDefinition getRoot( OperationDefinition.Operation operation )
{
  TypeDefinition root = null;
  SchemaDefinition schemaDefinition = findSchemaDefinition();
  if( schemaDefinition != null )
  {
    Optional<OperationTypeDefinition> rootQueryType =
      schemaDefinition.getOperationTypeDefinitions().stream()
        .filter( e -> e.getName().equals( getOperationKey( operation ) ) ).findFirst();
    if( rootQueryType.isPresent() )
    {
      Type type = rootQueryType.get().getTypeName();
      root = findTypeDefinition( type );
    }
  }
  if( root == null )
  {
    // e.g., by convention a 'type' named "Query" is considered the root query type
    // if one is not specified in the 'schema'
    root = _gqlManifold.findTypeDefinition( getOperationDefaultTypeName( operation ) );
  }
  return root;
}
 
Example 2
Source File: Operation.java    From graphql-spqr with Apache License 2.0 6 votes vote down vote up
public Operation(String name, AnnotatedType javaType, Type contextType, List<OperationArgument> arguments,
                 List<Resolver> resolvers, OperationDefinition.Operation operationType, boolean batched) {

    if (!(resolvers.stream().allMatch(Resolver::isBatched) || resolvers.stream().noneMatch(Resolver::isBatched))) {
        throw new IllegalArgumentException("Operation \"" + name + "\" mixes regular and batched resolvers");
    }
    
    this.name = name;
    this.description = resolvers.stream().map(Resolver::getOperationDescription).filter(Utils::isNotEmpty).findFirst().orElse(null);
    this.deprecationReason = resolvers.stream().map(Resolver::getOperationDeprecationReason).filter(Objects::nonNull).findFirst().orElse(null);
    this.typedElement = new TypedElement(javaType, resolvers.stream()
            .flatMap(resolver -> resolver.getTypedElement().getElements().stream())
            .distinct().collect(Collectors.toList()));
    this.contextType = contextType;
    this.resolversByFingerprint = collectResolversByFingerprint(resolvers);
    this.arguments = arguments;
    this.operationType = operationType;
    this.batched = batched;
}
 
Example 3
Source File: DefaultOperationBuilder.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
private Operation buildOperation(Type contextType, List<Resolver> resolvers, OperationDefinition.Operation operationType, GlobalEnvironment environment) {
    String name = resolveName(resolvers);
    AnnotatedType javaType = resolveJavaType(name, resolvers, environment.messageBundle);
    List<OperationArgument> arguments = collectArguments(name, resolvers);
    boolean batched = isBatched(resolvers);
    return new Operation(name, javaType, contextType, arguments, resolvers, operationType, batched);
}
 
Example 4
Source File: PublicResolverBuilder.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
private Collection<Resolver> buildMethodInvokers(ResolverBuilderParams params, BiPredicate<Method, ResolverBuilderParams> filter, OperationDefinition.Operation operation, boolean batchable) {
    MessageBundle messageBundle = params.getEnvironment().messageBundle;
    AnnotatedType beanType = params.getBeanType();
    Supplier<Object> querySourceBean = params.getQuerySourceBeanSupplier();
    Class<?> rawType = ClassUtils.getRawType(beanType.getType());
    if (rawType.isArray() || rawType.isPrimitive()) return Collections.emptyList();

    return Arrays.stream(rawType.getMethods())
            .filter(method -> filter.test(method, params))
            .filter(method -> params.getInclusionStrategy().includeOperation(Collections.singletonList(method), beanType))
            .filter(getFilters().stream().reduce(Predicate::and).orElse(ACCEPT_ALL))
            .map(method -> {
                TypedElement element = new TypedElement(getReturnType(method, params), method);
                OperationInfoGeneratorParams infoParams = new OperationInfoGeneratorParams(element, beanType, querySourceBean, messageBundle, operation);
                return new Resolver(
                        messageBundle.interpolate(operationInfoGenerator.name(infoParams)),
                        messageBundle.interpolate(operationInfoGenerator.description(infoParams)),
                        messageBundle.interpolate(ReservedStrings.decode(operationInfoGenerator.deprecationReason(infoParams))),
                        batchable && method.isAnnotationPresent(Batched.class),
                        querySourceBean == null ? new MethodInvoker(method, beanType) : new FixedMethodInvoker(querySourceBean, method, beanType),
                        element,
                        argumentBuilder.buildResolverArguments(
                                new ArgumentBuilderParams(method, beanType, params.getInclusionStrategy(), params.getTypeTransformer(), params.getEnvironment())),
                        method.isAnnotationPresent(GraphQLComplexity.class) ? method.getAnnotation(GraphQLComplexity.class).value() : null
                );
            })
            .collect(Collectors.toList());
}
 
Example 5
Source File: OperationInfoGeneratorParams.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
OperationInfoGeneratorParams(TypedElement element, AnnotatedType declaringType, Supplier<Object> instanceSupplier,
                             MessageBundle messageBundle, OperationDefinition.Operation operationType) {
    this.element = Objects.requireNonNull(element);
    this.declaringType = Objects.requireNonNull(declaringType);
    this.instanceSupplier = instanceSupplier;
    this.messageBundle = messageBundle != null ? messageBundle : EmptyMessageBundle.INSTANCE;
    this.operationType = operationType;
}
 
Example 6
Source File: GqlParentType.java    From manifold with Apache License 2.0 4 votes vote down vote up
private String getOperationDefaultTypeName( OperationDefinition.Operation operation )
{
  return ManStringUtil.capitalize( operation.name().toLowerCase() );
}
 
Example 7
Source File: GqlParentType.java    From manifold with Apache License 2.0 4 votes vote down vote up
@NotNull
private String getOperationKey( OperationDefinition.Operation operation )
{
  return operation.name().toLowerCase();
}
 
Example 8
Source File: Operation.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
public OperationDefinition.Operation getOperationType() {
    return operationType;
}
 
Example 9
Source File: OperationInfoGeneratorParams.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
public OperationDefinition.Operation getOperationType() {
    return operationType;
}
 
Example 10
Source File: OperationInfoGeneratorParams.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
public Builder withOperationType(OperationDefinition.Operation operationType) {
    this.operationType = operationType;
    return this;
}