private FieldDefAndDirectiveParams buildField(BuildContext buildCtx, TypeDefinition parentType, FieldDefinition fieldDef) { buildCtx.enterNode(fieldDef); GraphQLFieldDefinition.Builder builder = GraphQLFieldDefinition.newFieldDefinition(); builder.definition(fieldDef); builder.name(fieldDef.getName()); builder.description(schemaGeneratorHelper.buildDescription(fieldDef, fieldDef.getDescription())); builder.deprecate(schemaGeneratorHelper.buildDeprecationReason(fieldDef.getDirectives())); GraphQLDirective[] directives = buildDirectives(fieldDef.getDirectives(), Collections.emptyList(), DirectiveLocation.FIELD_DEFINITION, buildCtx.getDirectiveDefinitions()); builder.withDirectives( directives ); fieldDef.getInputValueDefinitions().forEach(inputValueDefinition -> builder.argument(buildArgument(buildCtx, inputValueDefinition))); GraphQLOutputType fieldType = buildOutputType(buildCtx, fieldDef.getType()); builder.type(fieldType); GraphQLFieldDefinition fieldDefinition = builder.build(); // if they have already wired in a fetcher - then leave it alone FieldCoordinates coordinates = FieldCoordinates.coordinates(parentType.getName(), fieldDefinition.getName()); if (!buildCtx.codeRegistry.hasDataFetcher(coordinates)) { DataFetcherFactory dataFetcherFactory = buildDataFetcherFactory(buildCtx, parentType, fieldDef, fieldType, Arrays.asList(directives)); buildCtx.getCodeRegistry().dataFetcher(coordinates, dataFetcherFactory); } return buildCtx.exitNode(new FieldDefAndDirectiveParams(fieldDefinition, buildCtx.mkBehaviourParams())); }
private FieldDefAndDirectiveParams buildField(BuildContext buildCtx, TypeDefinition parentType, FieldDefinition fieldDef) { buildCtx.enterNode(fieldDef); GraphQLFieldDefinition.Builder builder = GraphQLFieldDefinition.newFieldDefinition(); builder.definition(fieldDef); builder.name(fieldDef.getName()); builder.description(schemaGeneratorHelper.buildDescription(fieldDef, fieldDef.getDescription())); builder.deprecate(schemaGeneratorHelper.buildDeprecationReason(fieldDef.getDirectives())); GraphQLDirective[] directives = buildDirectives(fieldDef.getDirectives(), Collections.emptyList(), DirectiveLocation.FIELD_DEFINITION, buildCtx.getDirectiveDefinitions()); builder.withDirectives( directives ); fieldDef.getInputValueDefinitions().forEach(inputValueDefinition -> builder.argument(buildArgument(buildCtx, inputValueDefinition))); GraphQLOutputType fieldType = buildOutputType(buildCtx, fieldDef.getType()); builder.type(fieldType); GraphQLFieldDefinition fieldDefinition = builder.build(); // if they have already wired in a fetcher - then leave it alone FieldCoordinates coordinates = FieldCoordinates.coordinates(parentType.getName(), fieldDefinition.getName()); if (!buildCtx.codeRegistry.hasDataFetcher(coordinates)) { DataFetcherFactory dataFetcherFactory = buildDataFetcherFactory(buildCtx, parentType, fieldDef, fieldType, Arrays.asList(directives)); buildCtx.getCodeRegistry().dataFetcher(coordinates, dataFetcherFactory); } return buildCtx.exitNode(new FieldDefAndDirectiveParams(fieldDefinition, buildCtx.mkBehaviourParams())); }
public static Builder notNull (Builder aSource) { GraphQLFieldDefinition field = aSource.build(); return create(field.getName()).argument(field.getArguments()) .type(new GraphQLNonNull(field.getType())) .dataFetcher(field.getDataFetcher()) .definition(field.getDefinition()) .deprecate(field.getDeprecationReason()) .description(field.getDescription()); }