Skip to content
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

sveltekit support #229

Merged
merged 20 commits into from
Aug 30, 2021
Merged

sveltekit support #229

merged 20 commits into from
Aug 30, 2021

Conversation

PabloSzx
Copy link
Owner

@PabloSzx PabloSzx commented Aug 24, 2021

closes #146

@benbender if you want to collaborate on this you are more than welcome 👍

@vercel
Copy link

vercel bot commented Aug 24, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/theguild/graphql-ez/8GCgzXxpdUKdcYfu42C72kBCrxke
✅ Preview: https://graphql-ez-git-sveltekit-theguild.vercel.app

@PabloSzx
Copy link
Owner Author

@benbender Here is the first working version https://github.com/PabloSzx/graphql-ez/blob/sveltekit/examples/sveltekit/src/routes/graphql.ts if you want please take a look and test it and give opinions or suggestions https://github.com/PabloSzx/graphql-ez/blob/sveltekit/packages/sveltekit/main/src/index.ts

What I did to reduce the friction with the current node.js integrations is to create a fake IncomingMessage that only has access to "headers" and "method", which is what most of the integrations or envelop plugins use anyways

@benbender
Copy link
Collaborator

Hey! Thanks for the effort! I would love to play with it and so I'll just added an additional route with the newly created graphq-ez-handler into my play-project and it seems to work fine initially with a mildly complex schema generated by giraphql. Great job!

Problem atm seems to be that the sveltekit-integration isn't known to the core yet and therefor I can't test any plugins without patching the sveltekit-integration into the compatibility-list. Is there some kind of undocumented switch to turn off the compatibility check or something? And if not, might it be worth adding one for development?

@PabloSzx
Copy link
Owner Author

Hey! Thanks for the effort! I would love to play with it and so I'll just added an additional route with the newly created graphq-ez-handler into my play-project and it seems to work fine initially with a mildly complex schema generated by giraphql. Great job!

Problem atm seems to be that the sveltekit-integration isn't known to the core yet and therefor I can't test any plugins without patching the sveltekit-integration into the compatibility-list. Is there some kind of undocumented switch to turn off the compatibility check or something? And if not, might it be worth adding one for development?

the compatibility list doesn't make sense to turn off for the specific plugins that requires it because the "onIntegrationRegister" lifecycle has to be hardcoded for the integration that it supports 😞

@PabloSzx
Copy link
Owner Author

PabloSzx commented Aug 25, 2021

for the IDE plugins like graphiql and altair or voyager, the plugins will need to export an extra handler that adds support for sveltekit, it's not hard just reusing the existing handlers but adapted for the sveltekit format, but the altair requires a dynamic route

for the plugins:

  • upload
  • websockets
  • new sse

they are virtually impossible to add support for sveltekit 😞

@benbender
Copy link
Collaborator

What I had in mind was a simple option, probably undocumented, which just circumvents the checks entirely. Not meant to be used regularly, but just for development of new plugins/integrations.

So for example one could have something like:

    ezApp = createEZAppFactory(
      {
        integrationName: "sveltekit",
        disableCompatibilityChecks: true
      },
      appConfig
    );

And a check for it here:

if (compatibilityList && !compatibilityList.includes(integrationName)) {

@PabloSzx
Copy link
Owner Author

PabloSzx commented Aug 25, 2021

What I had in mind was a simple option, probably undocumented, which just circumvents the checks entirely. Not meant to be used regularly, but just for development of new plugins/integrations.

So for example one could have something like:

    ezApp = createEZAppFactory(
      {
        integrationName: "sveltekit",
        disableCompatibilityChecks: true
      },
      appConfig
    );

And a check for it here:

if (compatibilityList && !compatibilityList.includes(integrationName)) {

the compatibility list is only there for the lifecycle "onIntegrationRegister", the plugins that don't use that lifecycle, don't specify it, there isn't any purpose behind disabling them, and if you are creating new plugins, you can simply don't specify the compatibilityList field / not use onIntegrationRegister / add the integration you are working on to the list

the onIntegrationRegister uses integration specific context, that won't be available for the logic it uses, that is why the check is there

@benbender
Copy link
Collaborator

Thanks for the invite! I'll have a look onto altair/graphiql later today or tomorrow as I have some things to check on my todo-list beforehand...

There are also some slight issues with the typings of the new sveltekit-integration as, f.e., I'm using a global type for Locals which isn't correctly picked up by the Request/ServerRequest-type. I just noticed this while setting up my context...

For everything related to upload/multipart/streams in sveltekit, there might be some hope for the future as the Whatwg Streams-API gets more support (deno, node16, ...) and there are some quite active discussions about it at sveltejs/kit#1563, sveltejs/kit#2212 etc and there might also be a chance for some sort of support for connect-handlers before 1.0.

@benbender
Copy link
Collaborator

I've added the most primitive support for graphiql here.

Before going further, I wanted to ask, if there is any specific reason why you've split the routes for the nextjs-handler between graphql and graphiql?

The straight-forward way to implement compatibility for sveltekit, in the same manner like you did for nextjs, seems to be to duplicate the GraphiQLHandler-method and adapt it for sveltekit.

That approach seems repetitive to me and I would have opted for another approach to handle the split between the graphiql/graphql-handlers directly inside the graphql-ez-app - much like graphql-helix did with its shouldRenderGraphiQL()-method. Following that approach would enable the nextjs/sveltekit-integrations also to be simply added via the plugin-interface without having the need to add another route-handler...

@PabloSzx
Copy link
Owner Author

Before going further, I wanted to ask, if there is any specific reason why you've split the routes for the nextjs-handler between graphql and graphiql?

I don't think there is a specific reason for it, it was just more of an opinionated decision, I felt like going to graphiql should be a different path and 100% conscious decision, just like going to altair is, but I understand 100% that having it in the same path with logic like "if (shouldRenderGraphiQL(" is something a lot of people expect, I will work on it 👍 it might mean some changes for some integrations

@PabloSzx
Copy link
Owner Author

Before going further, I wanted to ask, if there is any specific reason why you've split the routes for the nextjs-handler between graphql and graphiql?

I don't think there is a specific reason for it, it was just more of an opinionated decision, I felt like going to graphiql should be a different path and 100% conscious decision, just like going to altair is, but I understand 100% that having it in the same path with logic like "if (shouldRenderGraphiQL(" is something a lot of people expect, I will work on it 👍 it might mean some changes for some integrations

#236 🎉 I want to update the graphiql instance to have the changes of contra/graphql-helix#44 & contra/graphql-helix#37 before merging tho 👌

@PabloSzx
Copy link
Owner Author

PabloSzx commented Aug 25, 2021

Now by default, the graphiql plugin points to the same path as the API, just like vanilla graphql-helix and apollo server does it👌

https://github.com/PabloSzx/graphql-ez/releases/tag/@graphql-ez/[email protected]

@PabloSzx
Copy link
Owner Author

PabloSzx commented Aug 29, 2021

There are also some slight issues with the typings of the new sveltekit-integration as, f.e., I'm using a global type for Locals which isn't correctly picked up by the Request/ServerRequest-type. I just noticed this while setting up my context...

@benbender what do you think is the solution for that, you are using those custom types in the "buildContext"?

I came up with this solution, a custom type that allows you to specify a custom locals

Screenshot from 2021-08-28 21-19-56

@changeset-bot
Copy link

changeset-bot bot commented Aug 29, 2021

🦋 Changeset detected

Latest commit: 3670f22

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 31 packages
Name Type
@graphql-ez/plugin-altair Minor
graphql-ez Patch
@pablosz/graphql-helix-graphiql Patch
@graphql-ez/plugin-graphiql Minor
@graphql-ez/plugin-voyager Minor
@graphql-ez/sveltekit Patch
@graphql-ez/cloudflare Patch
@graphql-ez/express Patch
@graphql-ez/express-testing Patch
@graphql-ez/fastify Patch
@graphql-ez/fastify-testing Patch
@graphql-ez/hapi Patch
@graphql-ez/hapi-testing Patch
@graphql-ez/http Patch
@graphql-ez/http-testing Patch
@graphql-ez/koa Patch
@graphql-ez/koa-testing Patch
@graphql-ez/nextjs Patch
@graphql-ez/nextjs-testing Patch
@graphql-ez/plugin-automatic-persisted-queries Patch
@graphql-ez/plugin-codegen Patch
@graphql-ez/plugin-dataloader Patch
@graphql-ez/plugin-modules Patch
@graphql-ez/plugin-scalars Patch
@graphql-ez/plugin-schema Patch
@graphql-ez/plugin-sse Patch
@graphql-ez/plugin-upload Patch
@graphql-ez/plugin-websockets Patch
@graphql-yoga/express Patch
graphql-yoga Patch
@graphql-yoga/preset Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat-request] Support Sveltekit?
2 participants