public GraphQLInterfaceType nodeInterface(TypeResolver typeResolver) { return newInterface() .name(NODE) .description("An object with an ID") .typeResolver(typeResolver) .field(newFieldDefinition() .name("id") .description("The ID of an object") .type(nonNull(GraphQLID))) .build(); }
public GraphQLFieldDefinition nodeField(GraphQLInterfaceType nodeInterface, DataFetcher nodeDataFetcher) { return newFieldDefinition() .name("node") .description("Fetches an object given its ID") .type(nodeInterface) .dataFetcher(nodeDataFetcher) .argument(newArgument() .name("id") .description("The ID of an object") .type(nonNull(GraphQLID))) .build(); }
private static Object serialize(GraphQLType type, Object value) { if (type instanceof GraphQLScalarType) { return ((GraphQLScalarType) type).getCoercing().serialize(value); } else { return ((GraphQLEnumType) type).getCoercing().serialize(value); } }
private void directWiring() { GraphQLFieldDefinition descriptionField = GraphQLFieldDefinition.newFieldDefinition() .name("description") .type(Scalars.GraphQLString) .dataFetcher(PropertyDataFetcher.fetching("desc")) .build(); }
public static GraphQLInputObjectType rangeType() { return GraphQLInputObjectType.newInputObject() .name("Range") .field(GraphQLInputObjectField.newInputObjectField() .name("lowerBound") .type(GraphQLInt)) .field(GraphQLInputObjectField.newInputObjectField() .name("upperBound") .type(GraphQLInt)) .build(); } }
@Override public Object get(DataFetchingEnvironment env) { String userId = env.getArgument("userId"); DataFetchingFieldSelectionSet selectionSet = env.getSelectionSet(); if (selectionSet.contains("user/*")) { return getUserAndTheirFriends(userId); } else { return getUser(userId); } } };
@Override public TraversalControl visitGraphQLObjectType(GraphQLObjectType node, TraverserContext<GraphQLType> context) { if (isTypeReference(node.getName())) { assertTypeUniqueness(node, result); } else { save(node.getName(), node); } return super.visitGraphQLObjectType(node, context); }
/** * Creates new field coordinates * * @param parentType the container of the field * @param fieldDefinition the field definition * * @return new field coordinates represented by the two parameters */ public static FieldCoordinates coordinates(GraphQLFieldsContainer parentType, GraphQLFieldDefinition fieldDefinition) { return new FieldCoordinates(parentType.getName(), fieldDefinition.getName()); }
@Override public TraversalControl visitGraphQLScalarType(GraphQLScalarType node, TraverserContext<GraphQLType> context) { assertTypeUniqueness(node, result); save(node.getName(), node); return super.visitGraphQLScalarType(node, context); }
@Override public TraversalControl visitGraphQLInputObjectType(GraphQLInputObjectType node, TraverserContext<GraphQLType> context) { if (isTypeReference(node.getName())) { assertTypeUniqueness(node, result); } else { save(node.getName(), node); } return super.visitGraphQLInputObjectType(node, context); }
@Override public TraversalControl visitGraphQLInterfaceType(GraphQLInterfaceType node, TraverserContext<GraphQLType> context) { if (isTypeReference(node.getName())) { assertTypeUniqueness(node, result); } else { save(node.getName(), node); } return super.visitGraphQLInterfaceType(node, context); }
@Override public TraversalControl visitGraphQLUnionType(GraphQLUnionType node, TraverserContext<GraphQLType> context) { assertTypeUniqueness(node, result); save(node.getName(), node); return super.visitGraphQLUnionType(node, context); }
@Override public TraversalControl visitGraphQLEnumType(GraphQLEnumType node, TraverserContext<GraphQLType> context) { assertTypeUniqueness(node, result); save(node.getName(), node); return super.visitGraphQLEnumType(node, context); }
DataFetcher getDataFetcher() { return dataFetcherFactory.get(newDataFetchingFactoryEnvironment() .fieldDefinition(this) .build()); }
@Override public TraversalControl visitGraphQLInputObjectField(GraphQLInputObjectField node, TraverserContext<GraphQLType> context) { node.replaceType((GraphQLInputType) resolvedType); return super.visitGraphQLInputObjectField(node, context); }
void interfaceType() { GraphQLInterfaceType comicCharacter = newInterface() .name("ComicCharacter") .description("A abstract comic character.") .field(newFieldDefinition() .name("name") .description("The name of the character.") .type(GraphQLString)) .build(); }
void inputTypes() { GraphQLInputObjectType inputObjectType = newInputObject() .name("inputObjectType") .field(newInputObjectField() .name("field") .type(GraphQLString)) .build(); }
private Object coerce(GraphQLType type, Object value) { if (value == null) { return null; } if (type instanceof GraphQLEnumType) { return ((GraphQLEnumType) type).getCoercing().serialize(value); } else { return ((GraphQLScalarType) type).getCoercing().serialize(value); } }