use of graphql.language.InputObjectTypeDefinition in project graphql-java by graphql-java.
the class GraphqlAntlrToLanguage method visitInputObjectTypeDefinition.
@Override
public Void visitInputObjectTypeDefinition(GraphqlParser.InputObjectTypeDefinitionContext ctx) {
InputObjectTypeDefinition def = new InputObjectTypeDefinition(ctx.name().getText());
newNode(def, ctx);
def.setDescription(newDescription(ctx.description()));
result.getDefinitions().add(def);
addContextProperty(ContextProperty.InputObjectTypeDefinition, def);
super.visitChildren(ctx);
popContext();
return null;
}
use of graphql.language.InputObjectTypeDefinition in project graphql-java by graphql-java.
the class IntrospectionResultToSchema method createInputObject.
@SuppressWarnings("unchecked")
InputObjectTypeDefinition createInputObject(Map<String, Object> input) {
assertTrue(input.get("kind").equals("INPUT_OBJECT"), "wrong input");
InputObjectTypeDefinition inputObjectTypeDefinition = new InputObjectTypeDefinition((String) input.get("name"));
inputObjectTypeDefinition.setComments(toComment((String) input.get("description")));
List<Map<String, Object>> fields = (List<Map<String, Object>>) input.get("inputFields");
List<InputValueDefinition> inputValueDefinitions = createInputValueDefinitions(fields);
inputObjectTypeDefinition.getInputValueDefinitions().addAll(inputValueDefinitions);
return inputObjectTypeDefinition;
}
use of graphql.language.InputObjectTypeDefinition in project graphql-java by graphql-java.
the class SchemaTypeChecker method checkInputValues.
private void checkInputValues(List<GraphQLError> errors, InputObjectTypeDefinition inputType, List<InputValueDefinition> inputValueDefinitions) {
// field unique ness
checkNamedUniqueness(errors, inputValueDefinitions, InputValueDefinition::getName, (name, inputValueDefinition) -> {
// not sure why this is needed but inlining breaks it
@SuppressWarnings("UnnecessaryLocalVariable") InputObjectTypeDefinition as = inputType;
return new NonUniqueNameError(as, inputValueDefinition);
});
// directive checks
inputValueDefinitions.forEach(inputValueDef -> checkNamedUniqueness(errors, inputValueDef.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(inputType, inputValueDef, directiveName)));
inputValueDefinitions.forEach(inputValueDef -> inputValueDef.getDirectives().forEach(directive -> {
checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(inputType, inputValueDef));
checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(inputType, inputValueDef, argumentName));
}));
}
use of graphql.language.InputObjectTypeDefinition in project graphql-java by graphql-java.
the class SchemaTypeExtensionsChecker method checkInputObjectTypeExtensions.
/*
* Input object type extensions have the potential to be invalid if incorrectly defined.
*
* The named type must already be defined and must be a Input Object type.
* All fields of an Input Object type extension must have unique names.
* All fields of an Input Object type extension must not already be a field of the original Input Object.
* Any directives provided must not already apply to the original Input Object type.
*/
private void checkInputObjectTypeExtensions(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry) {
typeRegistry.inputObjectTypeExtensions().forEach((name, extensions) -> {
checkTypeExtensionHasCorrespondingType(errors, typeRegistry, name, extensions, InputObjectTypeDefinition.class);
checkTypeExtensionDirectiveRedefinition(errors, typeRegistry, name, extensions, InputObjectTypeDefinition.class);
// field redefinitions
extensions.forEach(extension -> {
List<InputValueDefinition> inputValueDefinitions = extension.getInputValueDefinitions();
// field unique ness
checkNamedUniqueness(errors, inputValueDefinitions, InputValueDefinition::getName, (namedField, fieldDef) -> new NonUniqueNameError(extension, fieldDef));
// directive checks
inputValueDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(extension, fld, directiveName)));
inputValueDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> {
checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(extension, fld));
checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(extension, fld, argumentName));
}));
//
// fields must be unique within a type extension
forEachBut(extension, extensions, otherTypeExt -> checkForInputValueRedefinition(errors, otherTypeExt, otherTypeExt.getInputValueDefinitions(), inputValueDefinitions));
//
// then check for field re-defs from the base type
Optional<InputObjectTypeDefinition> baseTypeOpt = typeRegistry.getType(extension.getName(), InputObjectTypeDefinition.class);
baseTypeOpt.ifPresent(baseTypeDef -> checkForInputValueRedefinition(errors, extension, inputValueDefinitions, baseTypeDef.getInputValueDefinitions()));
});
});
}
use of graphql.language.InputObjectTypeDefinition in project graphql-java by graphql-java.
the class SchemaGenerator method buildInputType.
private GraphQLInputType buildInputType(BuildContext buildCtx, Type rawType) {
TypeDefinition typeDefinition = buildCtx.getTypeDefinition(rawType);
TypeInfo typeInfo = TypeInfo.typeInfo(rawType);
GraphQLInputType inputType = buildCtx.hasInputType(typeDefinition);
if (inputType != null) {
return typeInfo.decorate(inputType);
}
if (buildCtx.stackContains(typeInfo)) {
// we have circled around so put in a type reference and fix it later
return typeInfo.decorate(typeRef(typeInfo.getName()));
}
buildCtx.push(typeInfo);
if (typeDefinition instanceof InputObjectTypeDefinition) {
inputType = buildInputObjectType(buildCtx, (InputObjectTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof EnumTypeDefinition) {
inputType = buildEnumType(buildCtx, (EnumTypeDefinition) typeDefinition);
} else if (typeDefinition instanceof ScalarTypeDefinition) {
inputType = buildScalar(buildCtx, (ScalarTypeDefinition) typeDefinition);
} else {
// typeDefinition is not a valid InputType
throw new NotAnInputTypeError(typeDefinition);
}
buildCtx.put(inputType);
buildCtx.pop();
return typeInfo.decorate(inputType);
}
Aggregations