private GraphQLObjectType getObjectType(EntityType<?> entityType) { if (entityCache.containsKey(entityType)) return entityCache.get(entityType); GraphQLObjectType objectType = GraphQLObjectType.newObject() .name(entityType.getName()) .description(getSchemaDescription( entityType.getJavaType())) .fields(entityType.getAttributes().stream() .filter(this::isNotIgnored) .map(this::getObjectField) .collect(Collectors.toList()) ) .build(); entityCache.putIfAbsent(entityType, objectType); return objectType; }
private GraphQLObjectType getEmbeddableType(EmbeddableType<?> embeddableType) { if (embeddableCache.containsKey(embeddableType)) return embeddableCache.get(embeddableType); String embeddableTypeName = namingStrategy.singularize(embeddableType.getJavaType().getSimpleName())+"EmbeddableType"; GraphQLObjectType objectType = GraphQLObjectType.newObject() .name(embeddableTypeName) .description(getSchemaDescription( embeddableType.getJavaType())) .fields(embeddableType.getAttributes().stream() .filter(this::isNotIgnored) .map(this::getObjectField) .collect(Collectors.toList()) ) .build(); embeddableCache.putIfAbsent(embeddableType, objectType); return objectType; }
.name(PROMOTION_LEVEL) .withInterface(projectEntityInterface.getTypeRef()) .fields(projectEntityInterfaceFields())
@Override public GraphQLObjectType connectionType(String name, GraphQLObjectType edgeType, List<GraphQLFieldDefinition> connectionFields) { return newObject() .name(name + "Connection") .description("A connection to a list of items.") .field(newFieldDefinition() .name("edges") .description("a list of edges") .type(new GraphQLList(edgeType))) .field(newFieldDefinition() .name("nodes") .description("a list of nodes") .type(new GraphQLList(edgeType.getFieldDefinition("node").getType()))) .field(newFieldDefinition() .name("pageInfo") .description("details about this specific page") .type(new GraphQLNonNull(pageInfoType))) .field(newFieldDefinition() .name("totalCount") .description("number of nodes in connection") .type(GraphQLInt)) .fields(connectionFields) .build(); } }
@Override public GraphQLObjectType createType(GQLTypeCache cache) { return newObject() .name(PROMOTION_RUN) .withInterface(projectEntityInterface.getTypeRef()) .fields(projectEntityInterfaceFields()) .field( newFieldDefinition() .name("build") .description("Associated build") .type(new GraphQLNonNull(new GraphQLTypeReference(GQLTypeBuild.BUILD))) .build() ) // Promotion level .field( newFieldDefinition() .name("promotionLevel") .description("Associated promotion level") .type(new GraphQLNonNull(new GraphQLTypeReference(GQLTypePromotionLevel.PROMOTION_LEVEL))) .build() ) // OK .build(); }
public GraphQLFieldDefinition mutation(String name, String fieldName, List<GraphQLInputObjectField> inputFields, List<GraphQLFieldDefinition> outputFields, DataFetcher dataFetcher) { GraphQLInputObjectType inputObjectType = newInputObject() .name(name + "Input") .fields(inputFields) .build(); GraphQLObjectType outputType = newObject() .name(name + "Payload") .fields(outputFields) .build(); return newFieldDefinition() .name(fieldName) .type(outputType) .argument(newArgument() .name("input") .type(nonNull(inputObjectType))) .dataFetcher(dataFetcher) .build(); }
protected GraphQLOutputType generateOutputType(Object object) { //An enum is a special case in both java and graphql, //and must be checked for while generating other kinds of types GraphQLEnumType enumType = generateEnumType(object); if (enumType != null) { return enumType; } List<GraphQLFieldDefinition> fields = getOutputFieldDefinitions(object); if (fields == null || fields.isEmpty()) { return null; } String typeName = getGraphQLTypeNameOrIdentityCode(object); GraphQLObjectType.Builder builder = newObject() .name(typeName) .fields(fields) .description(getTypeDescription(object)); GraphQLInterfaceType[] interfaces = getInterfaces(object); if (interfaces != null) { builder.withInterfaces(interfaces); } return builder.build(); }
private GraphQLObjectType getQueryType() { GraphQLObjectType.Builder queryType = GraphQLObjectType.newObject() .name(this.name) .description(this.description); queryType.fields( entityManager.getMetamodel() .getEntities().stream() .filter(this::isNotIgnored) .map(this::getQueryFieldByIdDefinition) .collect(Collectors.toList()) ); queryType.fields( entityManager.getMetamodel() .getEntities().stream() .filter(this::isNotIgnored) .map(this::getQueryFieldSelectDefinition) .collect(Collectors.toList()) ); return queryType.build(); }
private GraphQLObjectType registerGraphQLType(TypeConfig type) { String typeName = type.getName(); String uri = this.hgqlSchema.getTypes().get(typeName).getId(); String description = "Instances of \"" + uri + "\"."; List<GraphQLFieldDefinition> builtFields = new ArrayList<>(); Map<String, FieldOfTypeConfig> fields = type.getFields(); Set<String> fieldNames = fields.keySet(); for (String fieldName : fieldNames) { builtFields.add(registerGraphQLField(type.getField(fieldName))); } builtFields.add(getidField()); builtFields.add(gettypeField()); return newObject() .name(typeName) .description(description) .fields(builtFields) .build(); }
private GraphQLObjectType registerGraphQLType(TypeConfig type) { String typeName = type.getName(); String uri = this.hgqlSchema.getTypes().get(typeName).getId(); String description = "Instances of \"" + uri + "\"."; List<GraphQLFieldDefinition> builtFields = new ArrayList<>(); Map<String, FieldOfTypeConfig> fields = type.getFields(); Set<String> fieldNames = fields.keySet(); for (String fieldName : fieldNames) { builtFields.add(registerGraphQLField(type.getField(fieldName))); } builtFields.add(getidField()); builtFields.add(gettypeField()); return newObject() .name(typeName) .description(description) .fields(builtFields) .build(); }
private GraphQLObjectType registerGraphQLQueryType(TypeConfig type) { String typeName = type.getName(); String description = "Top queryable predicates. " + "_GET queries return all objects of a given type, possibly restricted by limit and offset values. " + "_GET_BY_ID queries require a set of URIs to be specified."; List<GraphQLFieldDefinition> builtFields = new ArrayList<>(); Map<String, FieldOfTypeConfig> fields = type.getFields(); Set<String> fieldNames = fields.keySet(); for (String fieldName : fieldNames) { builtFields.add(registerGraphQLQueryField(type.getField(fieldName))); } return newObject() .name(typeName) .description(description) .fields(builtFields) .build(); }
private GraphQLObjectType registerGraphQLQueryType(TypeConfig type) { String typeName = type.getName(); String description = "Top queryable predicates. " + "_GET queries return all objects of a given type, possibly restricted by limit and offset values. " + "_GET_BY_ID queries require a set of URIs to be specified."; List<GraphQLFieldDefinition> builtFields = new ArrayList<>(); Map<String, FieldOfTypeConfig> fields = type.getFields(); Set<String> fieldNames = fields.keySet(); for (String fieldName : fieldNames) { builtFields.add(registerGraphQLQueryField(type.getField(fieldName))); } return newObject() .name(typeName) .description(description) .fields(builtFields) .build(); }
private void buildSchemaFromDefinitions(GraphQLObjectType.Builder queryBuilder, GraphQLObjectType.Builder mutationBuilder) { boolean foundQueryDefinitions = false; boolean foundMutationDefinitions = false; for(val graphQlFieldsDefinition : graphQlFieldsDefinitions){ val queryFields = graphQlFieldsDefinition.getQueryFields(); if (queryFields != null && queryFields.size() > 0) { queryBuilder = queryBuilder.fields(queryFields); foundQueryDefinitions = true; } val mutationFields = graphQlFieldsDefinition.getMutationFields(); if (mutationFields != null && mutationFields.size() > 0) { mutationBuilder = mutationBuilder.fields(mutationFields); foundMutationDefinitions = true; } } buildSchema(queryBuilder, mutationBuilder, foundQueryDefinitions, foundMutationDefinitions); }
public GraphQLObjectType connectionType(String name, GraphQLObjectType edgeType, List<GraphQLFieldDefinition> connectionFields) { return newObject() .name(name + "Connection") .description("A connection to a list of items.") .field(newFieldDefinition() .name("edges") .description("a list of edges") .type(list(edgeType))) .field(newFieldDefinition() .name("pageInfo") .description("details about this specific page") .type(nonNull(pageInfoType))) .fields(connectionFields) .build(); }
public GraphQLObjectType edgeType(String name, GraphQLOutputType nodeType, GraphQLInterfaceType nodeInterface, List<GraphQLFieldDefinition> edgeFields) { return newObject() .name(name + "Edge") .description("An edge in a connection") .field(newFieldDefinition() .name("node") .type(nodeType) .description("The item at the end of the edge")) .field(newFieldDefinition() .name("cursor") .type(nonNull(GraphQLString)) .description("cursor marks a unique position or index into the connection")) .fields(edgeFields) .build(); }
public GraphQLObjectType findSchemaMutations(DfsContext dfsContext, Class<?> implClass) { List<GraphQLFieldDefinition> graphQLFieldDefinitions = findSchemaMutationsFields(dfsContext, implClass); return newObject() .name(getGraphQLSchemaConfig().getSchemaMutationObjectName()) .fields(graphQLFieldDefinitions) .build(); }
public GraphQLFieldDefinition mutation(String name, String fieldName, List<GraphQLInputObjectField> inputFields, List<GraphQLFieldDefinition> outputFields, DataFetcher dataFetcher) { GraphQLInputObjectType inputObjectType = newInputObject() .name(name + "Input") .fields(inputFields) .build(); GraphQLObjectType outputType = newObject() .name(name + "Payload") .fields(outputFields) .build(); return newFieldDefinition() .name(fieldName) .type(outputType) .argument(newArgument() .name("input") .type(nonNull(inputObjectType))) .dataFetcher(dataFetcher) .build(); }
public GraphQLObjectType connectionType(String name, GraphQLObjectType edgeType, List<GraphQLFieldDefinition> connectionFields) { return newObject() .name(name + "Connection") .description("A connection to a list of items.") .field(newFieldDefinition() .name("edges") .description("a list of edges") .type(list(edgeType))) .field(newFieldDefinition() .name("pageInfo") .description("details about this specific page") .type(nonNull(pageInfoType))) .fields(connectionFields) .build(); }
public GraphQLObjectType edgeType(String name, GraphQLOutputType nodeType, GraphQLInterfaceType nodeInterface, List<GraphQLFieldDefinition> edgeFields) { return newObject() .name(name + "Edge") .description("An edge in a connection") .field(newFieldDefinition() .name("node") .type(nodeType) .description("The item at the end of the edge")) .field(newFieldDefinition() .name("cursor") .type(nonNull(GraphQLString)) .description("cursor marks a unique position or index into the connection")) .fields(edgeFields) .build(); }