11package graphql .schema .idl ;
22
3+ import graphql .Directives ;
34import graphql .GraphQLError ;
45import graphql .PublicApi ;
56import graphql .introspection .Introspection .DirectiveLocation ;
1819import graphql .language .OperationTypeDefinition ;
1920import graphql .language .ScalarTypeDefinition ;
2021import graphql .language .ScalarTypeExtensionDefinition ;
22+ import graphql .language .StringValue ;
2123import graphql .language .Type ;
2224import graphql .language .TypeDefinition ;
2325import graphql .language .TypeName ;
5456import graphql .schema .idl .errors .NotAnInputTypeError ;
5557import graphql .schema .idl .errors .NotAnOutputTypeError ;
5658import graphql .schema .idl .errors .SchemaProblem ;
59+ import graphql .util .FpKit ;
5760
5861import java .util .ArrayDeque ;
5962import java .util .ArrayList ;
@@ -120,6 +123,7 @@ public static Options defaultOptions() {
120123 * directive definition syntax before use.
121124 *
122125 * @param flag the value to use
126+ *
123127 * @return the new options
124128 */
125129 public Options enforceSchemaDirectives (boolean flag ) {
@@ -236,7 +240,9 @@ public SchemaGenerator() {
236240 *
237241 * @param typeRegistry this can be obtained via {@link SchemaParser#parse(String)}
238242 * @param wiring this can be built using {@link RuntimeWiring#newRuntimeWiring()}
243+ *
239244 * @return an executable schema
245+ *
240246 * @throws SchemaProblem if there are problems in assembling a schema such as missing type resolvers or no operations defined
241247 */
242248 public GraphQLSchema makeExecutableSchema (TypeDefinitionRegistry typeRegistry , RuntimeWiring wiring ) throws SchemaProblem {
@@ -250,15 +256,17 @@ public GraphQLSchema makeExecutableSchema(TypeDefinitionRegistry typeRegistry, R
250256 * @param options the controlling options
251257 * @param typeRegistry this can be obtained via {@link SchemaParser#parse(String)}
252258 * @param wiring this can be built using {@link RuntimeWiring#newRuntimeWiring()}
259+ *
253260 * @return an executable schema
261+ *
254262 * @throws SchemaProblem if there are problems in assembling a schema such as missing type resolvers or no operations defined
255263 */
256264 public GraphQLSchema makeExecutableSchema (Options options , TypeDefinitionRegistry typeRegistry , RuntimeWiring wiring ) throws SchemaProblem {
257265
258266 TypeDefinitionRegistry typeRegistryCopy = new TypeDefinitionRegistry ();
259267 typeRegistryCopy .merge (typeRegistry );
260268
261- schemaGeneratorHelper .addDeprecatedDirectiveDefinition (typeRegistryCopy );
269+ schemaGeneratorHelper .addDirectivesIncludedByDefault (typeRegistryCopy );
262270
263271 List <GraphQLError > errors = typeChecker .checkTypeRegistry (typeRegistryCopy , wiring , options .enforceSchemaDirectives );
264272 if (!errors .isEmpty ()) {
@@ -374,6 +382,7 @@ private GraphQLObjectType buildOperation(BuildContext buildCtx, OperationTypeDef
374382 * but then we build the rest of the types specified and put them in as additional types
375383 *
376384 * @param buildCtx the context we need to work out what we are doing
385+ *
377386 * @return the additional types not referenced from the top level operations
378387 */
379388 private Set <GraphQLType > buildAdditionalTypes (BuildContext buildCtx ) {
@@ -410,6 +419,7 @@ private Set<GraphQLDirective> buildAdditionalDirectives(BuildContext buildCtx) {
410419 *
411420 * @param buildCtx the context we need to work out what we are doing
412421 * @param rawType the type to be built
422+ *
413423 * @return an output type
414424 */
415425 @ SuppressWarnings ({"unchecked" , "TypeParameterUnusedInFormals" })
@@ -703,9 +713,13 @@ private GraphQLScalarType buildScalar(BuildContext buildCtx, ScalarTypeDefinitio
703713 scalar = scalar .transform (builder -> builder
704714 .definition (typeDefinition )
705715 .comparatorRegistry (buildCtx .getComparatorRegistry ())
706- .withDirectives (
707- buildDirectives (typeDefinition .getDirectives (),
708- directivesOf (extensions ), SCALAR , buildCtx .getDirectiveDefinitions (), buildCtx .getComparatorRegistry ())
716+ .specifiedBy (getSpecifiedByUrl (typeDefinition ))
717+ .withDirectives (buildDirectives (
718+ typeDefinition .getDirectives (),
719+ directivesOf (extensions ),
720+ SCALAR ,
721+ buildCtx .getDirectiveDefinitions (),
722+ buildCtx .getComparatorRegistry ())
709723 ));
710724 //
711725 // only allow modification of custom scalars
@@ -714,6 +728,15 @@ private GraphQLScalarType buildScalar(BuildContext buildCtx, ScalarTypeDefinitio
714728 return scalar ;
715729 }
716730
731+ private String getSpecifiedByUrl (ScalarTypeDefinition scalarTypeDefinition ) {
732+ Optional <Directive > specifiedByDirective = FpKit .findOne (scalarTypeDefinition .getDirectives (),
733+ directiveDefinition -> directiveDefinition .getName ().equals (Directives .SpecifiedByDirective .getName ()));
734+ return specifiedByDirective .map (directive -> {
735+ StringValue url = (StringValue ) directive .getArgument ("url" ).getValue ();
736+ return url .getValue ();
737+ }).orElse (null );
738+ }
739+
717740 private GraphQLFieldDefinition buildField (BuildContext buildCtx , TypeDefinition parentType , FieldDefinition
718741 fieldDef ) {
719742 GraphQLFieldDefinition .Builder builder = GraphQLFieldDefinition .newFieldDefinition ();
0 commit comments