Search in sources :

Example 1 with Definition

use of graphql.language.Definition in project graphql-java by graphql-java.

the class NoFragmentCycles method prepareFragmentMap.

private void prepareFragmentMap() {
    List<Definition> definitions = getValidationContext().getDocument().getDefinitions();
    for (Definition definition : definitions) {
        if (definition instanceof FragmentDefinition) {
            FragmentDefinition fragmentDefinition = (FragmentDefinition) definition;
            fragmentSpreads.put(fragmentDefinition.getName(), gatherSpreads(fragmentDefinition));
        }
    }
}
Also used : FragmentDefinition(graphql.language.FragmentDefinition) Definition(graphql.language.Definition) FragmentDefinition(graphql.language.FragmentDefinition)

Example 2 with Definition

use of graphql.language.Definition in project graphql-java by graphql-java.

the class ValidationContext method buildFragmentMap.

private void buildFragmentMap() {
    for (Definition definition : document.getDefinitions()) {
        if (!(definition instanceof FragmentDefinition))
            continue;
        FragmentDefinition fragmentDefinition = (FragmentDefinition) definition;
        fragmentDefinitionMap.put(fragmentDefinition.getName(), fragmentDefinition);
    }
}
Also used : FragmentDefinition(graphql.language.FragmentDefinition) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) Definition(graphql.language.Definition) FragmentDefinition(graphql.language.FragmentDefinition)

Example 3 with Definition

use of graphql.language.Definition in project graphql-java by graphql-java.

the class SchemaParser method buildRegistry.

/**
 * special method to build directly a TypeDefinitionRegistry from a Document
 * useful for Introspection =&gt; IDL (Document) =&gt; TypeDefinitionRegistry
 *
 * @param document containing type definitions
 *
 * @return the TypeDefinitionRegistry containing all type definitions from the document
 *
 * @throws SchemaProblem if an error occurs
 */
public TypeDefinitionRegistry buildRegistry(Document document) {
    List<GraphQLError> errors = new ArrayList<>();
    TypeDefinitionRegistry typeRegistry = new TypeDefinitionRegistry();
    List<Definition> definitions = document.getDefinitions();
    for (Definition definition : definitions) {
        typeRegistry.add(definition).ifPresent(errors::add);
    }
    if (errors.size() > 0) {
        throw new SchemaProblem(errors);
    } else {
        return typeRegistry;
    }
}
Also used : SchemaProblem(graphql.schema.idl.errors.SchemaProblem) ArrayList(java.util.ArrayList) Definition(graphql.language.Definition) GraphQLError(graphql.GraphQLError)

Aggregations

Definition (graphql.language.Definition)3 FragmentDefinition (graphql.language.FragmentDefinition)2 GraphQLError (graphql.GraphQLError)1 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)1 SchemaProblem (graphql.schema.idl.errors.SchemaProblem)1 ArrayList (java.util.ArrayList)1