Title: How to use custom directives alongside `graphql.java.extended.validation` · Issue #74 · graphql-java/graphql-java-extended-validation · GitHub
Open Graph Title: How to use custom directives alongside `graphql.java.extended.validation` · Issue #74 · graphql-java/graphql-java-extended-validation
X Title: How to use custom directives alongside `graphql.java.extended.validation` · Issue #74 · graphql-java/graphql-java-extended-validation
Description: Describe the bug When wiring the default graphql.java.extended.validation setup with the RuntimeWiringConfigurer provided by the new Spring for GraphQL project, custom directives that are registered via the builders directive() method do...
Open Graph Description: Describe the bug When wiring the default graphql.java.extended.validation setup with the RuntimeWiringConfigurer provided by the new Spring for GraphQL project, custom directives that are registere...
X Description: Describe the bug When wiring the default graphql.java.extended.validation setup with the RuntimeWiringConfigurer provided by the new Spring for GraphQL project, custom directives that are registere...
Opengraph URL: https://github.com/graphql-java/graphql-java-extended-validation/issues/74
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How to use custom directives alongside `graphql.java.extended.validation`","articleBody":"**Describe the bug**\r\nWhen wiring the default `graphql.java.extended.validation` setup with the `RuntimeWiringConfigurer` provided by the new `Spring for GraphQL` project, custom directives that are registered via the builders `directive()` method don't seem to apply anymore.\r\n\r\n**To Reproduce**\r\n\r\n1. Implement the official `graphql-java` [`DateFormattingDirective`](https://www.graphql-java.com/documentation/sdl-directives#another-example---date-formatting):\r\n\r\n```graphql\r\ndirective @DateFormat on FIELD_DEFINITION\r\n\r\ntype Person {\r\n id: ID!\r\n name: String!\r\n createdAt: String! @DateFormat\r\n}\r\n```\r\n\r\n```java\r\npublic class DateFormattingDirective implements SchemaDirectiveWiring {\r\n\r\n private static final String FORMAT = \"format\";\r\n\r\n @Override\r\n public GraphQLFieldDefinition onField(\r\n SchemaDirectiveWiringEnvironment\u003cGraphQLFieldDefinition> env) {\r\n\r\n GraphQLFieldDefinition fieldDefinition = env.getElement();\r\n GraphQLFieldsContainer fieldsContainer = env.getFieldsContainer();\r\n\r\n // DataFetcherFactories.wrapDataFetcher is a helper to wrap data fetchers so that\r\n // CompletionStage is handled correctly along with POJOs\r\n DataFetcher\u003c?> originalFetcher = env.getCodeRegistry()\r\n .getDataFetcher(fieldsContainer, fieldDefinition);\r\n DataFetcher\u003c?> dataFetcher = DataFetcherFactories.wrapDataFetcher(originalFetcher,\r\n ((dataFetchingEnvironment, value) -> {\r\n\r\n if (value instanceof LocalDateTime localDateTime\r\n && dataFetchingEnvironment.containsArgument(FORMAT)) {\r\n\r\n String dateTimePattern = dataFetchingEnvironment.getArgument(FORMAT);\r\n DateTimeFormatter dateTimeFormatter = buildFormatter(dateTimePattern);\r\n return dateTimeFormatter.format(localDateTime);\r\n }\r\n }\r\n\r\n return value;\r\n }));\r\n\r\n // This will extend the field by adding a new \"format\" argument to it for the date\r\n // formatting which allows clients to opt into.\r\n FieldCoordinates coordinates = FieldCoordinates.coordinates(fieldsContainer,\r\n fieldDefinition);\r\n env.getCodeRegistry().dataFetcher(coordinates, dataFetcher);\r\n\r\n return fieldDefinition.transform(builder -> builder.argument(\r\n GraphQLArgument.newArgument().name(FORMAT).type(Scalars.GraphQLString)));\r\n }\r\n\r\n private static DateTimeFormatter buildFormatter(String format) {\r\n return DateTimeFormatter.ofPattern(format);\r\n }\r\n}\r\n```\r\n\r\n2. Wire the custom `DateFormattingDirective` alongside the standard setup of the `graphql.java.extended.validation` project:\r\n\r\n```java\r\n@Configuration\r\npublic class GraphQLConfig {\r\n \r\n @Bean\r\n public RuntimeWiringConfigurer validationConfigurer() {\r\n ValidationRules validationRules = ValidationRules.newValidationRules()\r\n .onValidationErrorStrategy(OnValidationErrorStrategy.RETURN_NULL)\r\n .build();\r\n\r\n ValidationSchemaWiring schemaWiring = new ValidationSchemaWiring(validationRules);\r\n\r\n return builder -> builder.directiveWiring(schemaWiring).build();\r\n }\r\n\r\n @Bean\r\n public RuntimeWiringConfigurer directiveConfigurer() {\r\n return builder -> builder\r\n .directive(\"DateFormat\", new DateFormattingDirective())\r\n .build();\r\n }\r\n}\r\n``` \r\n\r\n3. See the functionality of the custom `DateFormattingDirective` disappear.\r\n\r\nWithout `graphql.java.extended.validation`:\r\n\r\n\r\nWith `graphql.java.extended.validation`:\r\n\r\n\r\n> Note, Registering both `graphql.java.extended.validation` `SchemaWiring` and `CustomDirective` inside a single `Bean` wont help either.","author":{"url":"https://github.com/paulbuechner","@type":"Person","name":"paulbuechner"},"datePublished":"2022-09-09T17:25:01Z","url":"https://github.com/graphql-java/graphql-java-extended-validation/issues/74"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:bd71e04b-395b-bce5-6ae0-2e4da75b8535 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CA4E:E3C4F:231CC41:2CC1A40:6B01866A |
| html-safe-nonce | 845a97760de35bd95edd4c1dd2f384cdbb4de7f3e8310c54d8b72769f9c956d6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTRFOkUzQzRGOjIzMUNDNDE6MkNDMUE0MDo2QjAxODY2QSIsInZpc2l0b3JfaWQiOiI3MzQwNjMzMzI3MjgxNDczMTMwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 559afa6c087c2ee63792ddbd92681641bf8c289e069dcd1793a8509ae50cd55e |
| hovercard-subject-tag | issue:1368122353 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/graphql-java/graphql-java-extended-validation/74/issue_layout |
| twitter:image | https://opengraph.githubassets.com/952302587d585b2d5d26b594624e401c2ad7c34b9b5880e840f9b1d650bdb81b/graphql-java/graphql-java-extended-validation/issues/74 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/952302587d585b2d5d26b594624e401c2ad7c34b9b5880e840f9b1d650bdb81b/graphql-java/graphql-java-extended-validation/issues/74 |
| og:image:alt | Describe the bug When wiring the default graphql.java.extended.validation setup with the RuntimeWiringConfigurer provided by the new Spring for GraphQL project, custom directives that are registere... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | paulbuechner |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/graphql-java/graphql-java-extended-validation git https://github.com/graphql-java/graphql-java-extended-validation.git |
| octolytics-dimension-user_id | 14289921 |
| octolytics-dimension-user_login | graphql-java |
| octolytics-dimension-repository_id | 205507809 |
| octolytics-dimension-repository_nwo | graphql-java/graphql-java-extended-validation |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 205507809 |
| octolytics-dimension-repository_network_root_nwo | graphql-java/graphql-java-extended-validation |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width