Search in sources :

Example 6 with GraphQLAppliedDirectiveArgument

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

the class SchemaGeneratorAppliedDirectiveHelper method transferMissingAppliedArguments.

private static List<GraphQLAppliedDirectiveArgument> transferMissingAppliedArguments(List<GraphQLAppliedDirectiveArgument> arguments, GraphQLDirective directiveDefinition) {
    Map<String, GraphQLAppliedDirectiveArgument> declaredArgs = FpKit.getByName(arguments, GraphQLAppliedDirectiveArgument::getName, FpKit.mergeFirst());
    List<GraphQLAppliedDirectiveArgument> argumentsOut = new ArrayList<>(arguments);
    for (GraphQLArgument directiveDefArg : directiveDefinition.getArguments()) {
        if (!declaredArgs.containsKey(directiveDefArg.getName())) {
            GraphQLAppliedDirectiveArgument.Builder missingArg = GraphQLAppliedDirectiveArgument.newArgument().name(directiveDefArg.getName()).type(directiveDefArg.getType()).description(directiveDefArg.getDescription());
            if (directiveDefArg.hasSetDefaultValue()) {
                missingArg.valueLiteral((Value<?>) directiveDefArg.getArgumentDefaultValue().getValue());
            }
            if (directiveDefArg.hasSetValue()) {
                missingArg.valueLiteral((Value<?>) directiveDefArg.getArgumentValue().getValue());
            }
            argumentsOut.add(missingArg.build());
        }
    }
    return argumentsOut;
}
Also used : ArrayList(java.util.ArrayList) GraphQLAppliedDirectiveArgument(graphql.schema.GraphQLAppliedDirectiveArgument) GraphQLArgument(graphql.schema.GraphQLArgument)

Example 7 with GraphQLAppliedDirectiveArgument

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

the class SchemaGeneratorAppliedDirectiveHelper method buildAppliedArg.

private static GraphQLAppliedDirectiveArgument buildAppliedArg(SchemaGeneratorHelper.BuildContext buildCtx, Argument arg, GraphQLDirective directiveDefinition) {
    GraphQLArgument directiveDefArgument = directiveDefinition.getArgument(arg.getName());
    GraphQLAppliedDirectiveArgument.Builder builder = GraphQLAppliedDirectiveArgument.newArgument();
    builder.name(arg.getName()).type(directiveDefArgument.getType()).definition(buildCtx.isCaptureAstDefinitions() ? arg : null);
    // we put the default value in if the specified is null
    if (arg.getValue() != null) {
        builder.valueLiteral(arg.getValue());
    } else {
        // we know it is a literal because it was created by SchemaGenerator
        if (directiveDefArgument.getArgumentDefaultValue().isSet()) {
            builder.valueLiteral((Value<?>) directiveDefArgument.getArgumentDefaultValue().getValue());
        }
    }
    return builder.build();
}
Also used : GraphQLAppliedDirectiveArgument(graphql.schema.GraphQLAppliedDirectiveArgument) GraphQLArgument(graphql.schema.GraphQLArgument)

Aggregations

GraphQLAppliedDirectiveArgument (graphql.schema.GraphQLAppliedDirectiveArgument)7 GraphQLArgument (graphql.schema.GraphQLArgument)6 GraphQLAppliedDirective (graphql.schema.GraphQLAppliedDirective)5 GraphQLDirective (graphql.schema.GraphQLDirective)5 ArrayList (java.util.ArrayList)5 PublicApi (graphql.PublicApi)4 ValuesResolver (graphql.execution.ValuesResolver)4 AstPrinter (graphql.language.AstPrinter)4 GraphQLObjectType (graphql.schema.GraphQLObjectType)4 GraphQLSchema (graphql.schema.GraphQLSchema)4 GraphQLSchemaElement (graphql.schema.GraphQLSchemaElement)4 GraphQLType (graphql.schema.GraphQLType)4 List (java.util.List)4 Assert.assertNotNull (graphql.Assert.assertNotNull)3 AssertException (graphql.AssertException)2 Directives (graphql.Directives)2 DirectivesUtil (graphql.DirectivesUtil)2 Scalars (graphql.Scalars)2 QueryTraverser (graphql.analysis.QueryTraverser)2 QueryVisitor (graphql.analysis.QueryVisitor)2