Search in sources :

Example 16 with GraphQLType

use of graphql.schema.GraphQLType in project graphql-java by graphql-java.

the class FieldCollector method doesFragmentConditionMatch.

private boolean doesFragmentConditionMatch(FieldCollectorParameters parameters, InlineFragment inlineFragment) {
    if (inlineFragment.getTypeCondition() == null) {
        return true;
    }
    GraphQLType conditionType;
    conditionType = getTypeFromAST(parameters.getGraphQLSchema(), inlineFragment.getTypeCondition());
    return checkTypeCondition(parameters, conditionType);
}
Also used : GraphQLType(graphql.schema.GraphQLType)

Example 17 with GraphQLType

use of graphql.schema.GraphQLType in project graphql-java by graphql-java.

the class FieldCollector method doesFragmentConditionMatch.

private boolean doesFragmentConditionMatch(FieldCollectorParameters parameters, FragmentDefinition fragmentDefinition) {
    GraphQLType conditionType;
    conditionType = getTypeFromAST(parameters.getGraphQLSchema(), fragmentDefinition.getTypeCondition());
    return checkTypeCondition(parameters, conditionType);
}
Also used : GraphQLType(graphql.schema.GraphQLType)

Example 18 with GraphQLType

use of graphql.schema.GraphQLType in project graphql-java by graphql-java.

the class SchemaPrinter method printComments.

private void printComments(PrintWriter out, Object graphQLType, String prefix) {
    AstDescriptionAndComments descriptionAndComments = getDescriptionAndComments(graphQLType);
    if (descriptionAndComments == null) {
        return;
    }
    Description astDescription = descriptionAndComments.descriptionAst;
    if (astDescription != null) {
        String quoteStr = "\"";
        if (astDescription.isMultiLine()) {
            quoteStr = "\"\"\"";
        }
        out.write(prefix);
        out.write(quoteStr);
        out.write(astDescription.getContent());
        out.write(quoteStr);
        out.write("\n");
        return;
    }
    if (descriptionAndComments.comments != null) {
        descriptionAndComments.comments.forEach(cmt -> {
            out.write(prefix);
            out.write("#");
            out.write(cmt.getContent());
            out.write("\n");
        });
    } else {
        String runtimeDescription = descriptionAndComments.runtimeDescription;
        if (!isNullOrEmpty(runtimeDescription)) {
            Stream<String> stream = Arrays.stream(runtimeDescription.split("\n"));
            stream.map(s -> prefix + "#" + s + "\n").forEach(out::write);
        }
    }
}
Also used : Arrays(java.util.Arrays) Node(graphql.language.Node) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLScalarType(graphql.schema.GraphQLScalarType) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLInterfaceType(graphql.schema.GraphQLInterfaceType) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) GraphQLUnionType(graphql.schema.GraphQLUnionType) GraphQLType(graphql.schema.GraphQLType) GraphQLEnumValueDefinition(graphql.schema.GraphQLEnumValueDefinition) Supplier(java.util.function.Supplier) AstValueHelper(graphql.language.AstValueHelper) Stack(java.util.Stack) LinkedHashMap(java.util.LinkedHashMap) Description(graphql.language.Description) Map(java.util.Map) GraphQLSchema(graphql.schema.GraphQLSchema) Assert(graphql.Assert) GraphQLObjectType(graphql.schema.GraphQLObjectType) PrintWriter(java.io.PrintWriter) GraphQLDirective(graphql.schema.GraphQLDirective) DEFAULT_FIELD_VISIBILITY(graphql.schema.visibility.DefaultGraphqlFieldVisibility.DEFAULT_FIELD_VISIBILITY) GraphQLNonNull(graphql.schema.GraphQLNonNull) GraphqlFieldVisibility(graphql.schema.visibility.GraphqlFieldVisibility) StringWriter(java.io.StringWriter) GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLOutputType(graphql.schema.GraphQLOutputType) GraphQLArgument(graphql.schema.GraphQLArgument) Collectors.joining(java.util.stream.Collectors.joining) AstPrinter(graphql.language.AstPrinter) Document(graphql.language.Document) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Comment(graphql.language.Comment) GraphQLList(graphql.schema.GraphQLList) Stream(java.util.stream.Stream) PublicApi(graphql.PublicApi) GraphQLEnumType(graphql.schema.GraphQLEnumType) Comparator(java.util.Comparator) Description(graphql.language.Description)

Example 19 with GraphQLType

use of graphql.schema.GraphQLType in project graphql-java by graphql-java.

the class VariableTypesMatchRule method checkVariable.

@Override
public void checkVariable(VariableReference variableReference) {
    VariableDefinition variableDefinition = variableDefinitionMap.get(variableReference.getName());
    if (variableDefinition == null) {
        return;
    }
    GraphQLType variableType = TypeFromAST.getTypeFromAST(getValidationContext().getSchema(), variableDefinition.getType());
    if (variableType == null) {
        return;
    }
    GraphQLInputType expectedType = getValidationContext().getInputType();
    if (expectedType == null) {
        // we must have a unknown variable say to not have a known type
        return;
    }
    if (!variablesTypesMatcher.doesVariableTypesMatch(variableType, variableDefinition.getDefaultValue(), expectedType)) {
        GraphQLType effectiveType = variablesTypesMatcher.effectiveType(variableType, variableDefinition.getDefaultValue());
        String message = String.format("Variable type '%s' doesn't match expected type '%s'", GraphQLTypeUtil.getUnwrappedTypeName(effectiveType), GraphQLTypeUtil.getUnwrappedTypeName(expectedType));
        addError(ValidationErrorType.VariableTypeMismatch, variableReference.getSourceLocation(), message);
    }
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) VariableDefinition(graphql.language.VariableDefinition) GraphQLType(graphql.schema.GraphQLType)

Example 20 with GraphQLType

use of graphql.schema.GraphQLType in project graphql-java by graphql-java.

the class TraversalContext method enterImpl.

private void enterImpl(FragmentDefinition fragmentDefinition) {
    enterName(fragmentDefinition.getName());
    GraphQLType type = schema.getType(fragmentDefinition.getTypeCondition().getName());
    addOutputType((GraphQLOutputType) type);
}
Also used : GraphQLType(graphql.schema.GraphQLType)

Aggregations

GraphQLType (graphql.schema.GraphQLType)24 GraphQLList (graphql.schema.GraphQLList)6 GraphQLNonNull (graphql.schema.GraphQLNonNull)5 GraphQLObjectType (graphql.schema.GraphQLObjectType)5 GraphQLInputObjectType (graphql.schema.GraphQLInputObjectType)4 GraphQLInputType (graphql.schema.GraphQLInputType)4 LinkedHashMap (java.util.LinkedHashMap)4 TypeName (graphql.language.TypeName)3 GraphQLEnumType (graphql.schema.GraphQLEnumType)3 GraphQLInputObjectField (graphql.schema.GraphQLInputObjectField)3 GraphQLScalarType (graphql.schema.GraphQLScalarType)3 GraphqlFieldVisibility (graphql.schema.visibility.GraphqlFieldVisibility)3 ArrayList (java.util.ArrayList)3 Stack (java.util.Stack)3 PublicApi (graphql.PublicApi)2 ArrayValue (graphql.language.ArrayValue)2 InputObjectTypeDefinition (graphql.language.InputObjectTypeDefinition)2 Value (graphql.language.Value)2 GraphQLCompositeType (graphql.schema.GraphQLCompositeType)2 HashMap (java.util.HashMap)2