@Override public TypeResolver getTypeResolver(InterfaceWiringEnvironment environment) { return env -> env.getSchema().getQueryType(); }
@Override public TypeResolver getTypeResolver(UnionWiringEnvironment environment) { return env -> env.getSchema().getQueryType(); }
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 TypePrinter<GraphQLSchema> schemaPrinter() { return (out, type, visibility) -> { GraphQLObjectType queryType = type.getQueryType(); GraphQLObjectType mutationType = type.getMutationType(); GraphQLObjectType subscriptionType = type.getSubscriptionType();
private GraphQLFieldDefinition getFieldDef(GraphQLSchema schema, GraphQLType parentType, Field field) { if (schema.getQueryType().equals(parentType)) { if (field.getName().equals(SchemaMetaFieldDef.getName())) { return SchemaMetaFieldDef; } if (field.getName().equals(TypeMetaFieldDef.getName())) { return TypeMetaFieldDef; } } if (field.getName().equals(TypeNameMetaFieldDef.getName()) && (parentType instanceof GraphQLObjectType || parentType instanceof GraphQLInterfaceType || parentType instanceof GraphQLUnionType)) { return TypeNameMetaFieldDef; } if (parentType instanceof GraphQLFieldsContainer) { return schema.getFieldVisibility().getFieldDefinition((GraphQLFieldsContainer) parentType, field.getName()); } return null; } }
if (schema.getQueryType() == parentType) { if (fieldName.equals(SchemaMetaFieldDef.getName())) { return SchemaMetaFieldDef;
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); }
@Override public String[] getQueries() { return configuration.getInvocationInputFactory().getSchemaProvider().getSchema().getQueryType().getFieldDefinitions().stream().map(GraphQLFieldDefinition::getName).toArray(String[]::new); }
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?"); } } }
private GraphQLObjectType getOperationRootType(GraphQLSchema graphQLSchema, OperationDefinition operationDefinition) { if (operationDefinition.getOperation() == OperationDefinition.Operation.MUTATION) { return graphQLSchema.getMutationType(); } else if (operationDefinition.getOperation() == OperationDefinition.Operation.QUERY) { return graphQLSchema.getQueryType(); } else { throw new GraphQLException(); } }
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(); }
@Test public void simpleConnection_buildSchema_TypeOfSimpleConnectionIsGraphQLList() throws Exception { GraphQLObjectType object = GraphQLAnnotations.object(MainConnection.class); GraphQLSchema schema = newSchema().query(object).build(); String objsTypeName = schema.getQueryType().getFieldDefinition("objs").getType().getName(); assertThat(objsTypeName, is("ObjChunk")); }
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(); }