-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add AsyncIterable support to fetcher function #1724
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1724 +/- ##
==========================================
- Coverage 67.07% 66.77% -0.31%
==========================================
Files 87 87
Lines 4839 4873 +34
Branches 1330 1343 +13
==========================================
+ Hits 3246 3254 +8
- Misses 1359 1383 +24
- Partials 234 236 +2
Continue to review full report at Codecov.
|
} else if (isAsyncIterable(fetch)) { | ||
(async () => { | ||
try { | ||
for await (const result of fetch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be all fine given that we don't support IE11 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all of this will be passed through browserslist and babel anyways
also to note re: for await of
: afaik this will gaurantee serial execution, this is desired?
this looks great! im just wondering how we can best demonstrate this feature at this point? maybe just a quick entry in the readme showing the two alternatives to fetcher? or a docs/fetcher.md for some more in depth examples? been thinking of this as a way to break down the super long readme and to prepare for a docsite eventually, i’d like to have a docsite where we could show many graphiql props permutations. we could use storybook or play room or use some other strategy. |
For starters, we could just add another example to the readme directly calls |
Right now I tested the implementation by starting the GraphiQL dev server and pasting the following into <script>
// graphql-js relies on the global process object without feature detection :(
window.process = globalThis.process = {
env: {
NODE_ENV: "development"
}
}
</script>
<script type="module">
import * as graphql from "https://unpkg.com/[email protected]/index.mjs?module"
const schema = new graphql.GraphQLSchema({
mutation: new graphql.GraphQLObjectType({
name: "Mutation",
fields: {
ping: {
type: graphql.GraphQLBoolean,
resolve: () => true
}
}
}),
query: new graphql.GraphQLObjectType({
name: "Query",
fields: {
ping: {
type: graphql.GraphQLBoolean,
resolve: () => true
}
}
}),
subscription: new graphql.GraphQLObjectType({
name: "Subscription",
fields: {
count: {
type: graphql.GraphQLInt,
subscribe: async function * () {
for (let counter = 0; counter < 10; counter++) {
yield { count: counter };
await new Promise(res => setTimeout(res, 1000))
}
}
}
}
}),
});
const fetcher = (graphQLParams) => {
const document = graphql.parse(graphQLParams.query);
const operation = graphql.getOperationAST(document, graphQLParams.operationName);
if (operation.operation === "subscription") {
// AsyncIterable
return graphql.subscribe(
schema,
document,
{},
{},
graphQLParams.variables,
graphQLParams.operationName
)
}
// Promise or AsyncIterable
return graphql.execute(
schema,
document,
{},
{},
graphQLParams.variables,
graphQLParams.operationName
)
}
window.schemaFetcherContext = {
schema,
fetcher
}
</script> You will also have to adjust |
thats nice to see it working, but we will need to keep that example as is for now. lets just keep it to that readme entry for now, and we will come up with a way to show more detailed examples soon! |
Yeah, I just want some way for you to properly test before shipping a broken GraphiQL :D I am currently working on the readme section. In the meantime, I also fixed some issues that I could identify with the custom fetcher. |
528ec05
to
e18ba6c
Compare
@n1ru4l perhaps for now let's implement it in one of the examples, and then we can cross-reference to that from the readme? |
so in summary, the two last steps:
|
now available in |
No description provided.