private void checkForFieldRedefinition(List<GraphQLError> errors, TypeDefinition typeDefinition, List<FieldDefinition> fieldDefinitions, List<FieldDefinition> referenceFieldDefinitions) { Map<String, FieldDefinition> referenceMap = FpKit.getByName(referenceFieldDefinitions, FieldDefinition::getName, mergeFirst()); fieldDefinitions.forEach(fld -> { FieldDefinition reference = referenceMap.get(fld.getName()); if (referenceMap.containsKey(fld.getName())) { // ok they have the same field but is it the same type if (!isSameType(fld.getType(), reference.getType())) { errors.add(new TypeExtensionFieldRedefinitionError(typeDefinition, fld)); } } }); }
errors.add(new MissingInterfaceFieldError(typeOfType, objectTypeDef, interfaceTypeDef, interfaceFieldDef)); } else { if (!typeRegistry.isSubTypeOf(objectFieldDef.getType(), interfaceFieldDef.getType())) { String interfaceFieldType = AstPrinter.printAst(interfaceFieldDef.getType()); String objectFieldType = AstPrinter.printAst(objectFieldDef.getType()); errors.add(new InterfaceFieldRedefinitionError(typeOfType, objectTypeDef, interfaceTypeDef, objectFieldDef, objectFieldType, interfaceFieldType));
private Builder(FieldDefinition existing) { this.sourceLocation = existing.getSourceLocation(); this.name = existing.getName(); this.comments = existing.getComments(); this.type = existing.getType(); this.description = existing.getDescription(); this.inputValueDefinitions = existing.getInputValueDefinitions(); this.directives = existing.getDirectives(); this.ignoredChars = existing.getIgnoredChars(); }
private NodePrinter<FieldDefinition> fieldDefinition() { final String argSep = compactMode ? "," : ", "; return (out, node) -> { out.printf("%s", comments(node)); String args; if (hasComments(node.getInputValueDefinitions()) && !compactMode) { args = join(node.getInputValueDefinitions(), "\n"); out.printf("%s", node.getName() + wrap("(\n", args, "\n)") + ": " + spaced( type(node.getType()), directives(node.getDirectives()) ) ); } else { args = join(node.getInputValueDefinitions(), argSep); out.printf("%s", node.getName() + wrap("(", args, ")") + ": " + spaced( type(node.getType()), directives(node.getDirectives()) ) ); } }; }
private void checkField(DiffCtx ctx, TypeDefinition old, FieldDefinition oldField, FieldDefinition newField) { Type oldFieldType = oldField.getType(); Type newFieldType = newField.getType(); DiffCategory category = checkTypeWithNonNullAndList(oldFieldType, newFieldType); if (category != null) { ctx.report(DiffEvent.apiBreakage() .category(category) .typeName(old.getName()) .typeKind(getTypeKind(old)) .fieldName(oldField.getName()) .components(getAstDesc(oldFieldType), getAstDesc(newFieldType)) .reasonMsg("The new API has changed field '%s' from type '%s' to '%s'", mkDotName(old.getName(), oldField.getName()), getAstDesc(oldFieldType), getAstDesc(newFieldType)) .build()); } checkFieldArguments(ctx, old, oldField, oldField.getInputValueDefinitions(), newField.getInputValueDefinitions()); checkDirectives(ctx, old, oldField.getDirectives(), newField.getDirectives()); // // and down we go again recursively via fields // checkType(ctx, oldFieldType, newFieldType); }
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 void checkForFieldRedefinition(List<GraphQLError> errors, TypeDefinition typeDefinition, List<FieldDefinition> fieldDefinitions, List<FieldDefinition> referenceFieldDefinitions) { Map<String, FieldDefinition> referenceMap = FpKit.getByName(referenceFieldDefinitions, FieldDefinition::getName, mergeFirst()); fieldDefinitions.forEach(fld -> { FieldDefinition reference = referenceMap.get(fld.getName()); if (referenceMap.containsKey(fld.getName())) { // ok they have the same field but is it the same type if (!isSameType(fld.getType(), reference.getType())) { errors.add(new TypeExtensionFieldRedefinitionError(typeDefinition, fld)); } } }); }
private void addImports(Collection<String> imports, ObjectTypeDefinition def) { for ( FieldDefinition fieldDef : def.getFieldDefinitions() ) { addImports(imports, fieldDef.getType()); } }
private void addImports(Collection<String> imports, InterfaceTypeDefinition def) { for ( FieldDefinition fieldDef : def.getFieldDefinitions() ) { addImports(imports, fieldDef.getType()); } }
private List<Field> getFields(ObjectTypeDefinition def) { List<Field> fields = new ArrayList<Field>(); for ( FieldDefinition fieldDef : def.getFieldDefinitions() ) { Field field = new Field(fieldDef.getName(), toJavaTypeName(fieldDef.getType())); field.graphQLType = toGraphQLType(fieldDef.getType()); field.dataResolver = toDataResolver(fieldDef.getType()); field.args = toArgs(fieldDef.getInputValueDefinitions()); fields.add(field); } return fields; }
private List<Field> getFields(InterfaceTypeDefinition def) { List<Field> fields = new ArrayList<Field>(); for ( FieldDefinition fieldDef : def.getFieldDefinitions() ) { Field field = new Field(fieldDef.getName(), toJavaTypeName(fieldDef.getType())); field.args = toArgs(fieldDef.getInputValueDefinitions()); fields.add(field); } return fields; }
errors.add(new MissingInterfaceFieldError(typeOfType, objectTypeDef, interfaceTypeDef, interfaceFieldDef)); } else { if (!typeRegistry.isSubTypeOf(objectFieldDef.getType(), interfaceFieldDef.getType())) { String interfaceFieldType = AstPrinter.printAst(interfaceFieldDef.getType()); String objectFieldType = AstPrinter.printAst(objectFieldDef.getType()); errors.add(new InterfaceFieldRedefinitionError(typeOfType, objectTypeDef, interfaceTypeDef, objectFieldDef, objectFieldType, interfaceFieldType));
private Builder(FieldDefinition existing) { this.sourceLocation = existing.getSourceLocation(); this.name = existing.getName(); this.comments = existing.getComments(); this.type = existing.getType(); this.description = existing.getDescription(); this.inputValueDefinitions = existing.getInputValueDefinitions(); this.directives = existing.getDirectives(); this.ignoredChars = existing.getIgnoredChars(); }
private NodePrinter<FieldDefinition> fieldDefinition() { final String argSep = compactMode ? "," : ", "; return (out, node) -> { out.printf("%s", comments(node)); String args; if (hasComments(node.getInputValueDefinitions()) && !compactMode) { args = join(node.getInputValueDefinitions(), "\n"); out.printf("%s", node.getName() + wrap("(\n", args, "\n)") + ": " + spaced( type(node.getType()), directives(node.getDirectives()) ) ); } else { args = join(node.getInputValueDefinitions(), argSep); out.printf("%s", node.getName() + wrap("(", args, ")") + ": " + spaced( type(node.getType()), directives(node.getDirectives()) ) ); } }; }
rdfSchema.insertObjectTriple(serviceURI, RDF_TYPE, HGQL_SERVICE); String outputTypeUri = getOutputType(field.getType()); rdfSchema.insertObjectTriple(fieldURI, HGQL_OUTPUT_TYPE, outputTypeUri);
rdfSchema.insertObjectTriple(serviceURI, RDF_TYPE, HGQL_SERVICE); String outputTypeUri = getOutputType(field.getType()); rdfSchema.insertObjectTriple(fieldURI, HGQL_OUTPUT_TYPE, outputTypeUri);
private void checkField(DiffCtx ctx, TypeDefinition old, FieldDefinition oldField, FieldDefinition newField) { Type oldFieldType = oldField.getType(); Type newFieldType = newField.getType(); DiffCategory category = checkTypeWithNonNullAndList(oldFieldType, newFieldType); if (category != null) { ctx.report(DiffEvent.apiBreakage() .category(category) .typeName(old.getName()) .typeKind(getTypeKind(old)) .fieldName(oldField.getName()) .components(getAstDesc(oldFieldType), getAstDesc(newFieldType)) .reasonMsg("The new API has changed field '%s' from type '%s' to '%s'", mkDotName(old.getName(), oldField.getName()), getAstDesc(oldFieldType), getAstDesc(newFieldType)) .build()); } checkFieldArguments(ctx, old, oldField, oldField.getInputValueDefinitions(), newField.getInputValueDefinitions()); checkDirectives(ctx, old, oldField.getDirectives(), newField.getDirectives()); // // and down we go again recursively via fields // checkType(ctx, oldFieldType, newFieldType); }
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())); }