private void enterImpl(Directive directive) { this.directive = schema.getDirective(directive.getName()); }
@Override public void checkDirective(Directive directive, List<Node> ancestors) { GraphQLDirective graphQLDirective = getValidationContext().getSchema().getDirective(directive.getName()); if (graphQLDirective == null) { String message = String.format("Unknown directive %s", directive.getName()); addError(ValidationErrorType.UnknownDirective, directive.getSourceLocation(), message); return; } Node ancestor = ancestors.get(ancestors.size() - 1); if (hasInvalidLocation(graphQLDirective, ancestor)) { String message = String.format("Directive %s not allowed here", directive.getName()); addError(ValidationErrorType.MisplacedDirective, directive.getSourceLocation(), message); } }
private void enterImpl(Directive directive) { this.directive = schema.getDirective(directive.getName()); }
@Override public void checkDirective(Directive directive, List<Node> ancestors) { GraphQLDirective graphQLDirective = getValidationContext().getSchema().getDirective(directive.getName()); if (graphQLDirective == null) { String message = String.format("Unknown directive %s", directive.getName()); addError(ValidationErrorType.UnknownDirective, directive.getSourceLocation(), message); return; } Node ancestor = ancestors.get(ancestors.size() - 1); if (hasInvalidLocation(graphQLDirective, ancestor)) { String message = String.format("Directive %s not allowed here", directive.getName()); addError(ValidationErrorType.MisplacedDirective, directive.getSourceLocation(), message); } }
@Override public Object getArgumentValue(ArgumentInjectorParams params) { GraphQLDirective descriptor = params.getParameter().getAnnotation(GraphQLDirective.class); boolean allDirectives = GenericTypeReflector.isSuperType(Collection.class, params.getType().getType()); ResolutionEnvironment env = params.getResolutionEnvironment(); String fallBackDirectiveName = env.globalEnvironment.typeInfoGenerator.generateDirectiveTypeName(params.getBaseType(), env.globalEnvironment.messageBundle); String directiveName = Utils.coalesce(descriptor.name(), fallBackDirectiveName); Stream<Introspection.DirectiveLocation> locations = descriptor.locations().length != 0 ? Arrays.stream(descriptor.locations()) : sortedLocations(params.getResolutionEnvironment().dataFetchingEnvironment.getGraphQLSchema().getDirective(directiveName).validLocations()); Directives directives = env.getDirectives(); Stream<Map<String, Object>> rawValues = locations .map(loc -> directives.find(loc, directiveName)) .filter(Objects::nonNull) .flatMap(Collection::stream); Object deserializableValue = allDirectives ? rawValues.collect(Collectors.toList()) : rawValues.findFirst().orElse(null); if (deserializableValue == null) { return null; } return params.getResolutionEnvironment().valueMapper.fromInput(deserializableValue, params.getType()); }
private Map<String, Object> parseDirective(Directive dir, DataFetchingEnvironment env) { GraphQLDirective directive = env.getExecutionContext().getGraphQLSchema().getDirective(dir.getName()); if (directive == null) { return null; } return Collections.unmodifiableMap( valuesResolver.getArgumentValues(env.getGraphQLSchema().getFieldVisibility(), directive.getArguments(), dir.getArguments(), env.getExecutionContext().getVariables())); }