MichalLytek / type-graphql

Create GraphQL schema and resolvers with TypeScript, using classes and decorators!
https://typegraphql.com
MIT License
8.05k stars 676 forks source link

Subscriptions with Apollo-Server v3+ #1005

Open CoryBall opened 3 years ago

CoryBall commented 3 years ago

With Apollo-Server version 3 forward (NPM shows it released about 2 months ago), the base apollo-server package no longer includes a "batteries-included" subscription server. You have to switch to an integrated package like apollo-server-express and implement your own using the http and subscriptions-transport-ws packages.

The current documentation explaining how to set up a subscription server with express shows different configuration than previous versions for the base new ApolloServer(), throwing some obvious errors.

Is there a current timeline for resolving this? I'm not sure how to go about fixing this myself with a PR, I was just wondering if this was already part of an upcoming release, or if it hasn't been noticed yet.

MichalLytek commented 3 years ago

TypeGraphQL doesn't maintain docs of Apollo Server. TypeGraphQL is library agnostic, you can use GraphQL Helix, express-graphql or whatever you want. I don't see any point of repeating the docs of Apollo Server about the complex subscriptions setup.

Is there a current timeline for resolving this? I

I'm not sure what you're asking for 🤔

CoryBall commented 3 years ago

I'm talking about this page in TypeGraphQL's docs showing how to use TypeGraphQL with Apollo to set up subscriptions, which no longer works.

MichalLytek commented 3 years ago

It stil works, only with Apollo Server v2. All we can do is to: 1) Duplicate long apollo docs 2) Add info that it's for v2 3) Remove this chapter totally, let's people setup it by itself 4) Switch all examples and docs to GraphQL Helix or something else

CoryBall commented 3 years ago
  1. Doesn't make sense to monitor and duplicate another service's documentation
  2. If users are starting a new project, they'll most likely want to use the latest stable version. If its an existing project, then they can read Apollo's docs.
  3. This makes the most sense to me.
  4. This might be good short-term, but the same issue is bound to happen. Maybe someone (I have no interest in using Helix, I have no other issues using Apollo at the moment) can create an example repo for TypeGraphQL to show.

Whatever ends up happening I'll continue to use TypeGraphQL, I don't think the Decorators and integration for subscriptions in resolvers are affected, and setting up a subscription server is not TypeGraphQL's job to baby users through. Thanks for the library!

AaronNGray commented 3 years ago

@MichalLytek - What do type-graphql subscriptions not work with Apollo version 2 ? Is it something that can be fixed and if not why not ? And does this effect Apollo version 3 using graphql-ws ?

MichalLytek commented 3 years ago

@AaronNGray It's been working with Apollo v2 for 3 years.

It also works with Apollo v3, I've recently upgraded one project: https://gitlab.com/tezgraph/tezgraph

AaronNGray commented 3 years ago

@MichalLytek - Thanks, that is relieving to hear ! The code is highly abstracted compared to normal examples.

AaronNGray commented 3 years ago

I dont see any use of @Subscrition in the code !

MichalLytek commented 3 years ago

@AaronNGray TypeGraphQL has nothing in common with Apollo v2 or v3. It provides a graphql-js compatible schema.

Apollo v3 changes requires only changes in Apollo Server setup. Completely 0 changes needed for your resolvers or @Subscribe.

AaronNGray commented 3 years ago

@MichalLytek - I put my issue over on https://github.com/MichalLytek/type-graphql/discussions/1018 as I don't use StackOverflow out of principle. The issue I am having is with the @Subscription code I think as it works as a normal subscriptions on both v2 and v3.

MartinMuzatko commented 3 years ago

I'd recommend to just put a link to here: https://www.apollographql.com/docs/apollo-server/data/subscriptions/#enabling-subscriptions I was able to follow their instructions quite well.

sgentile commented 2 years ago

Does anyone have an example of using graphql-ws with apollo server / typegraphql ? https://www.apollographql.com/docs/apollo-server/data/subscriptions/#the-graphql-ws-transport-library

AaronNGray commented 2 years ago

Here we go :-

https://github.com/AaronNGray/fullstack-apollo-graph-ws-subscription-type-graphql-example

Hope this helps !

It uses this package I made on the client side :-

https://github.com/AaronNGray/apollo-client-graphql-ws https://www.npmjs.com/package/apollo-client-graphql-ws

sgentile commented 2 years ago

Perfect - thank you!

AaronNGray commented 2 years ago

On Tuesday, 21 December 2021, Steve Gentile @.***> wrote:

Perfect - thank you!

Not quite, there's a reasonable number of security holes in the used modules. I have not got round to looking at them properly.

-- Aaron Gray

Independent Open Source Software Engineer, Computer Language Researcher, Information Theorist, and Computer Scientist.

voidcenter commented 2 years ago

Maybe a package.json file can be added here: https://github.com/MichalLytek/type-graphql/tree/master/examples/simple-subscriptions so that we know what version of apollo-server works with the example?

MichalLytek commented 2 years ago

@voidcenter Examples uses dependencies from the root node_modules, so see devDependencies section of the main package.json

rafaell-lycan commented 2 years ago

What about graphql-ws?