-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
README about DataFetcher definitions
- Loading branch information
1 parent
25cbb95
commit 0c9db2d
Showing
1 changed file
with
34 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,12 +19,41 @@ implement any suitable dynamic mechanism to provide it. | |
|
||
---- | ||
|
||
## Next Steps | ||
## Decorating the schemas with DataFetcher definitions | ||
|
||
With dynamic schemas, I think the mapping of types and/or fields to DataFetchers belongs in them. | ||
|
||
We can use structured comments in the schemas for this so that they stay syntactically valid. | ||
|
||
Here's an example where `## fetch:` comments are used for these definitions: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
stefangrimm
Contributor
|
||
|
||
type Query { | ||
|
||
# Use the 'test:pipe' Fetcher where "test" is a Fetcher namespace, | ||
# and pass "$" to it as a data selection expression which in this | ||
# case means "use the current Sling Resource". | ||
currentResource : SlingResource ## fetch:test/pipe $ | ||
|
||
} | ||
|
||
type SlingResource { | ||
path: String | ||
resourceType: String | ||
|
||
# Use the "test:digest" DataFetcher with the "md5" fetcher option | ||
# and pass "$path" as its data selection expression | ||
pathMD5: String ## fetch:test/digest/md5 $.path | ||
|
||
# Similar with different fetcher options | ||
pathSHA512: String ## fetch:test/digest/sha512,armored(UTF-8) $.path | ||
} | ||
|
||
A default `DataFetcher` is used for types and fields which have no `## fetch:` comment. | ||
|
||
This is **not yet implemented** at commit 25cbb95d, there's just a basic parser for the above | ||
fetch definitions. | ||
|
||
|
||
* This is just a rough prototype for now, in "the tests are green, who cares?" style. | ||
* We'll probably need to invent a way to specify which `DataFetchers` to use in the schemas, for example decorating | ||
them with information on how to select a suitable `DataFetchers` OSGi service based on service properties. | ||
|
||
## Multiple GraphQL endpoint styles | ||
|
||
This module enables the following GraphQL "styles" | ||
|
After experimenting a bit with this syntax, I'd like to suggest the following adjustment:
Comment-based annotations should be placed before the field definition. In that case, we can leverage
graphql-java
to do the general parsing and useFieldDefinition.getComments()
to access the comments. This doesn't work if we use the suggested "suffix-based approach, as the comments would be attributed to the wrong field definition.If we stick to the suggested syntax, we would probably have to implement our own GraphQL (pre-) parser, which is something I would like to avoid at almost any cost.
A data fetcher would then defined like this:
@bdelacretaz WDYT?