Map<String, GraphQLType> allTypes(final GraphQLSchema schema, final Set<GraphQLType> additionalTypes) { List<GraphQLType> roots = new ArrayList<>(); roots.add(schema.getQueryType()); if (schema.isSupportingMutations()) { roots.add(schema.getMutationType()); } if (schema.isSupportingSubscriptions()) { roots.add(schema.getSubscriptionType()); } if (additionalTypes != null) { roots.addAll(additionalTypes); } if (schema.getDirectives() != null) { roots.addAll(schema.getDirectives()); } roots.add(Introspection.__Schema); GraphQLTypeCollectingVisitor visitor = new GraphQLTypeCollectingVisitor(); TRAVERSER.depthFirst(visitor, roots); return visitor.getResult(); }
GraphQLObjectType queryType = type.getQueryType(); GraphQLObjectType mutationType = type.getMutationType(); GraphQLObjectType subscriptionType = type.getSubscriptionType();
private GraphQLObjectType getRootTypeFromOperation(OperationDefinition operationDefinition) { switch (operationDefinition.getOperation()) { case MUTATION: return assertNotNull(schema.getMutationType()); case QUERY: return assertNotNull(schema.getQueryType()); case SUBSCRIPTION: return assertNotNull(schema.getSubscriptionType()); default: return assertShouldNeverHappen(); } }
private void enterImpl(OperationDefinition operationDefinition) { if (operationDefinition.getOperation() == OperationDefinition.Operation.MUTATION) { addOutputType(schema.getMutationType()); } else if (operationDefinition.getOperation() == OperationDefinition.Operation.QUERY) { addOutputType(schema.getQueryType()); } else if (operationDefinition.getOperation() == OperationDefinition.Operation.SUBSCRIPTION) { addOutputType(schema.getSubscriptionType()); } else { Assert.assertShouldNeverHappen(); } }
public Set<SchemaValidationError> validateSchema(GraphQLSchema schema) { SchemaValidationErrorCollector validationErrorCollector = new SchemaValidationErrorCollector(); checkTypes(schema, validationErrorCollector); traverse(schema.getQueryType(), rules, validationErrorCollector); if (schema.isSupportingMutations()) { traverse(schema.getMutationType(), rules, validationErrorCollector); } if (schema.isSupportingSubscriptions()) { traverse(schema.getSubscriptionType(), rules, validationErrorCollector); } return validationErrorCollector.getErrors(); }
public static GraphQLObjectType getOperationRootType(GraphQLSchema graphQLSchema, OperationDefinition operationDefinition) { OperationDefinition.Operation operation = operationDefinition.getOperation(); if (operation == MUTATION) { GraphQLObjectType mutationType = graphQLSchema.getMutationType(); if (mutationType == null) { throw new MissingRootTypeException("Schema is not configured for mutations.", operationDefinition.getSourceLocation()); } return mutationType; } else if (operation == QUERY) { GraphQLObjectType queryType = graphQLSchema.getQueryType(); if (queryType == null) { throw new MissingRootTypeException("Schema does not define the required query root type.", operationDefinition.getSourceLocation()); } return queryType; } else if (operation == SUBSCRIPTION) { GraphQLObjectType subscriptionType = graphQLSchema.getSubscriptionType(); if (subscriptionType == null) { throw new MissingRootTypeException("Schema is not configured for subscriptions.", operationDefinition.getSourceLocation()); } return subscriptionType; } else { return assertShouldNeverHappen("Unhandled case. An extra operation enum has been added without code support"); } }
private GraphQLObjectType getOperationRootType(GraphQLSchema graphQLSchema, OperationDefinition operationDefinition) { OperationDefinition.Operation operation = operationDefinition.getOperation(); if (operation == MUTATION) { GraphQLObjectType mutationType = graphQLSchema.getMutationType(); if (mutationType == null) { throw new MissingRootTypeException("Schema is not configured for mutations.", operationDefinition.getSourceLocation()); } return mutationType; } else if (operation == QUERY) { GraphQLObjectType queryType = graphQLSchema.getQueryType(); if (queryType == null) { throw new MissingRootTypeException("Schema does not define the required query root type.", operationDefinition.getSourceLocation()); } return queryType; } else if (operation == SUBSCRIPTION) { GraphQLObjectType subscriptionType = graphQLSchema.getSubscriptionType(); if (subscriptionType == null) { throw new MissingRootTypeException("Schema is not configured for subscriptions.", operationDefinition.getSourceLocation()); } return subscriptionType; } else { return assertShouldNeverHappen("Unhandled case. An extra operation enum has been added without code support"); } } }
/** * This allows you to build a schema from an existing schema. It copies everything from the existing * schema and then allows you to replace them. * * @param existingSchema the existing schema * * @return a new schema builder */ public static Builder newSchema(GraphQLSchema existingSchema) { return new Builder() .query(existingSchema.getQueryType()) .mutation(existingSchema.getMutationType()) .subscription(existingSchema.getSubscriptionType()) .codeRegistry(existingSchema.getCodeRegistry()) .clearAdditionalTypes() .clearDirectives() .additionalDirectives(existingSchema.directives) .additionalTypes(existingSchema.additionalTypes); }
private GraphQLObjectType getRootType(GraphQLSchema schema, OperationDefinition operationDefinition) { if (operationDefinition.getOperation() == OperationDefinition.Operation.MUTATION) { return Objects.requireNonNull(schema.getMutationType()); } else if (operationDefinition.getOperation() == OperationDefinition.Operation.QUERY) { return Objects.requireNonNull(schema.getQueryType()); } else if (operationDefinition.getOperation() == OperationDefinition.Operation.SUBSCRIPTION) { return Objects.requireNonNull(schema.getSubscriptionType()); } else { throw new IllegalStateException("Unknown operation type encountered. Incompatible graphql-java version?"); } } }
@Override public Object convertOutput(Publisher<T> original, AnnotatedType type, ResolutionEnvironment resolutionEnvironment) { //Subscriptions are expected to return a Publisher directly, so no conversion needed if (resolutionEnvironment.dataFetchingEnvironment.getParentType() == resolutionEnvironment.dataFetchingEnvironment.getGraphQLSchema().getSubscriptionType()) { return original; } //Otherwise, convert the Publisher into a CompletableFuture return convertOutputForNonSubscription(original, type, resolutionEnvironment); }
@Override public Object convertOutput(Mono<T> original, AnnotatedType type, ResolutionEnvironment resolutionEnvironment) { //For subscriptions, Mono<T> (Publisher<T>) should be returned directly if (resolutionEnvironment.dataFetchingEnvironment.getParentType() == resolutionEnvironment.dataFetchingEnvironment.getGraphQLSchema().getSubscriptionType()) { return original; } //For other operations it must be converted into a CompletableFuture<T> return original.toFuture(); }
@Override public Object convertOutput(Mono<T> original, AnnotatedType type, ResolutionEnvironment resolutionEnvironment) { //For subscriptions, Mono<T> (Publisher<T>) should be returned directly if (resolutionEnvironment.dataFetchingEnvironment.getParentType() == resolutionEnvironment.dataFetchingEnvironment.getGraphQLSchema().getSubscriptionType()) { return original; } //For other operations it must be converted into a CompletableFuture<T> return original.toFuture(); }
Map<String, GraphQLType> allTypes(final GraphQLSchema schema, final Set<GraphQLType> additionalTypes) { List<GraphQLType> roots = new ArrayList<>(); roots.add(schema.getQueryType()); if (schema.isSupportingMutations()) { roots.add(schema.getMutationType()); } if (schema.isSupportingSubscriptions()) { roots.add(schema.getSubscriptionType()); } if (additionalTypes != null) { roots.addAll(additionalTypes); } if (schema.getDirectives() != null) { roots.addAll(schema.getDirectives()); } roots.add(Introspection.__Schema); GraphQLTypeCollectingVisitor visitor = new GraphQLTypeCollectingVisitor(); TRAVERSER.depthFirst(visitor, roots); return visitor.getResult(); }
private GraphQLObjectType getRootTypeFromOperation(OperationDefinition operationDefinition) { switch (operationDefinition.getOperation()) { case MUTATION: return assertNotNull(schema.getMutationType()); case QUERY: return assertNotNull(schema.getQueryType()); case SUBSCRIPTION: return assertNotNull(schema.getSubscriptionType()); default: return assertShouldNeverHappen(); } }
static GraphQLSchema copyReadOnly(GraphQLSchema schema) { return GraphQLSchema.newSchema() .query(schema.getQueryType()) .subscription(schema.getSubscriptionType()) .additionalTypes(schema.getAdditionalTypes()) .build(); }
private void enterImpl(OperationDefinition operationDefinition) { if (operationDefinition.getOperation() == OperationDefinition.Operation.MUTATION) { addOutputType(schema.getMutationType()); } else if (operationDefinition.getOperation() == OperationDefinition.Operation.QUERY) { addOutputType(schema.getQueryType()); } else if (operationDefinition.getOperation() == OperationDefinition.Operation.SUBSCRIPTION) { addOutputType(schema.getSubscriptionType()); } else { Assert.assertShouldNeverHappen(); } }
public Set<SchemaValidationError> validateSchema(GraphQLSchema schema) { SchemaValidationErrorCollector validationErrorCollector = new SchemaValidationErrorCollector(); checkTypes(schema, validationErrorCollector); traverse(schema.getQueryType(), rules, validationErrorCollector); if (schema.isSupportingMutations()) { traverse(schema.getMutationType(), rules, validationErrorCollector); } if (schema.isSupportingSubscriptions()) { traverse(schema.getSubscriptionType(), rules, validationErrorCollector); } return validationErrorCollector.getErrors(); }
public static GraphQLObjectType getOperationRootType(GraphQLSchema graphQLSchema, OperationDefinition operationDefinition) { OperationDefinition.Operation operation = operationDefinition.getOperation(); if (operation == MUTATION) { GraphQLObjectType mutationType = graphQLSchema.getMutationType(); if (mutationType == null) { throw new MissingRootTypeException("Schema is not configured for mutations.", operationDefinition.getSourceLocation()); } return mutationType; } else if (operation == QUERY) { GraphQLObjectType queryType = graphQLSchema.getQueryType(); if (queryType == null) { throw new MissingRootTypeException("Schema does not define the required query root type.", operationDefinition.getSourceLocation()); } return queryType; } else if (operation == SUBSCRIPTION) { GraphQLObjectType subscriptionType = graphQLSchema.getSubscriptionType(); if (subscriptionType == null) { throw new MissingRootTypeException("Schema is not configured for subscriptions.", operationDefinition.getSourceLocation()); } return subscriptionType; } else { return assertShouldNeverHappen("Unhandled case. An extra operation enum has been added without code support"); } }
private GraphQLObjectType getOperationRootType(GraphQLSchema graphQLSchema, OperationDefinition operationDefinition) { OperationDefinition.Operation operation = operationDefinition.getOperation(); if (operation == MUTATION) { GraphQLObjectType mutationType = graphQLSchema.getMutationType(); if (mutationType == null) { throw new MissingRootTypeException("Schema is not configured for mutations.", operationDefinition.getSourceLocation()); } return mutationType; } else if (operation == QUERY) { GraphQLObjectType queryType = graphQLSchema.getQueryType(); if (queryType == null) { throw new MissingRootTypeException("Schema does not define the required query root type.", operationDefinition.getSourceLocation()); } return queryType; } else if (operation == SUBSCRIPTION) { GraphQLObjectType subscriptionType = graphQLSchema.getSubscriptionType(); if (subscriptionType == null) { throw new MissingRootTypeException("Schema is not configured for subscriptions.", operationDefinition.getSourceLocation()); } return subscriptionType; } else { return assertShouldNeverHappen("Unhandled case. An extra operation enum has been added without code support"); } } }
/** * This allows you to build a schema from an existing schema. It copies everything from the existing * schema and then allows you to replace them. * * @param existingSchema the existing schema * * @return a new schema builder */ public static Builder newSchema(GraphQLSchema existingSchema) { return new Builder() .query(existingSchema.getQueryType()) .mutation(existingSchema.getMutationType()) .subscription(existingSchema.getSubscriptionType()) .codeRegistry(existingSchema.getCodeRegistry()) .clearAdditionalTypes() .clearDirectives() .additionalDirectives(existingSchema.directives) .additionalTypes(existingSchema.additionalTypes); }