use of graphql.language.TypeName in project graphql-java by graphql-java.
the class SchemaTypeExtensionsChecker method checkUnionTypeExtensions.
/*
* Union type extensions have the potential to be invalid if incorrectly defined.
*
* The named type must already be defined and must be a Union type.
* The member types of a Union type extension must all be Object base types; Scalar, Interface and Union types must not be member types of a Union. Similarly, wrapping types must not be member types of a Union.
* All member types of a Union type extension must be unique.
* All member types of a Union type extension must not already be a member of the original Union type.
* Any directives provided must not already apply to the original Union type.
*/
private void checkUnionTypeExtensions(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry) {
typeRegistry.unionTypeExtensions().forEach((name, extensions) -> {
checkTypeExtensionHasCorrespondingType(errors, typeRegistry, name, extensions, UnionTypeDefinition.class);
checkTypeExtensionDirectiveRedefinition(errors, typeRegistry, name, extensions, UnionTypeDefinition.class);
extensions.forEach(extension -> {
List<TypeName> memberTypes = extension.getMemberTypes().stream().map(t -> TypeInfo.typeInfo(t).getTypeName()).collect(Collectors.toList());
checkNamedUniqueness(errors, memberTypes, TypeName::getName, (namedMember, memberType) -> new NonUniqueNameError(extension, namedMember));
memberTypes.forEach(memberType -> {
Optional<ObjectTypeDefinition> unionTypeDefinition = typeRegistry.getType(memberType, ObjectTypeDefinition.class);
if (!unionTypeDefinition.isPresent()) {
errors.add(new MissingTypeError("union member", extension, memberType));
}
});
});
});
}
use of graphql.language.TypeName in project graphql-java by graphql-java.
the class TraversalContext method enterImpl.
private void enterImpl(InlineFragment inlineFragment) {
TypeName typeCondition = inlineFragment.getTypeCondition();
GraphQLOutputType type;
if (typeCondition != null) {
type = (GraphQLOutputType) schema.getType(typeCondition.getName());
} else {
type = (GraphQLOutputType) getParentType();
}
addOutputType(type);
}
use of graphql.language.TypeName in project graphql-java by graphql-java.
the class SchemaGenerator method buildAdditionalTypes.
/**
* We build the query / mutation / subscription path as a tree of referenced types
* but then we build the rest of the types specified and put them in as additional types
*
* @param buildCtx the context we need to work out what we are doing
*
* @return the additional types not referenced from the top level operations
*/
private Set<GraphQLType> buildAdditionalTypes(BuildContext buildCtx) {
Set<GraphQLType> additionalTypes = new HashSet<>();
TypeDefinitionRegistry typeRegistry = buildCtx.getTypeRegistry();
typeRegistry.types().values().forEach(typeDefinition -> {
TypeName typeName = new TypeName(typeDefinition.getName());
if (typeDefinition instanceof InputObjectTypeDefinition) {
if (buildCtx.hasInputType(typeDefinition) == null) {
additionalTypes.add(buildInputType(buildCtx, typeName));
}
} else {
if (buildCtx.hasOutputType(typeDefinition) == null) {
additionalTypes.add(buildOutputType(buildCtx, typeName));
}
}
});
return additionalTypes;
}
use of graphql.language.TypeName in project graphql-java by graphql-java.
the class GraphqlAntlrToLanguage method visitTypeName.
// MARKER END: Here GraphqlOperation.g4 specific methods end
@Override
public Void visitTypeName(GraphqlParser.TypeNameContext ctx) {
TypeName typeName = new TypeName(ctx.name().getText());
newNode(typeName, ctx);
for (ContextEntry contextEntry : contextStack) {
if (contextEntry.value instanceof ListType) {
((ListType) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.value instanceof NonNullType) {
((NonNullType) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.value instanceof VariableDefinition) {
((VariableDefinition) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.value instanceof FieldDefinition) {
((FieldDefinition) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.value instanceof InputValueDefinition) {
((InputValueDefinition) contextEntry.value).setType(typeName);
break;
}
if (contextEntry.contextProperty == ContextProperty.ObjectTypeDefinition) {
((ObjectTypeDefinition) contextEntry.value).getImplements().add(typeName);
break;
}
if (contextEntry.contextProperty == ContextProperty.UnionTypeDefinition) {
((UnionTypeDefinition) contextEntry.value).getMemberTypes().add(typeName);
break;
}
if (contextEntry.contextProperty == ContextProperty.OperationTypeDefinition) {
((OperationTypeDefinition) contextEntry.value).setType(typeName);
break;
}
}
return super.visitTypeName(ctx);
}
use of graphql.language.TypeName in project graphql-java by graphql-java.
the class GraphqlAntlrToLanguage method visitFragmentDefinition.
@Override
public Void visitFragmentDefinition(GraphqlParser.FragmentDefinitionContext ctx) {
FragmentDefinition fragmentDefinition = new FragmentDefinition();
newNode(fragmentDefinition, ctx);
fragmentDefinition.setName(ctx.fragmentName().getText());
fragmentDefinition.setTypeCondition(new TypeName(ctx.typeCondition().typeName().getText()));
addContextProperty(ContextProperty.FragmentDefinition, fragmentDefinition);
result.getDefinitions().add(fragmentDefinition);
super.visitFragmentDefinition(ctx);
popContext();
return null;
}
Aggregations