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

Update docs for meteor/apollo v3 #3739

Merged
merged 4 commits into from
Aug 17, 2018
Merged

Conversation

lorensr
Copy link
Contributor

@lorensr lorensr commented Jul 26, 2018

v3: apollographql/meteor-integration#124

Will release when this is merged. Maybe there's a better way to connect to WebApp, maybe @abernix knows? Currently recommending:

const server = new ApolloServer({...})

server.applyMiddleware({
  app: WebApp.connectHandlers,
  path: '/graphql'
})

// We are doing this work-around because Playground sets headers and WebApp also sets headers
// Resulting into a conflict and a server side exception of "Headers already sent"
WebApp.connectHandlers.use('/graphql', (req, res) => {
  if (req.method === 'GET') {
    res.end()
  }
})

@hwillson
Copy link
Member

Thanks for this @lorensr! Actually, we've been talking about the Meteor integration docs a fair bit recently. Given that you're planning on releasing a 3.0.0 version of https://github.com/apollographql/meteor-integration, does that mean you (or someone else) will be supporting/maintaining it? We were under the impression that it is currently unmaintained (due to the repo's README), and we were planning on completely removing most of Apollo's Meteor integration section. We were going to instead replace that full section with a single page, that links to modern and maintained community approaches for integrating Meteor and Apollo. As things stand currently, our preference is to point people towards using https://github.com/Swydo/ddp-apollo, since it's actively maintained. If someone is taking over the apollo package though, great!

So long story short - if the apollo package is going to be maintained by someone, we'll definitely get these changes merged in. If it's not though, we're likely moving ahead with reducing this section greatly. Let me know - thanks!

@lorensr
Copy link
Contributor Author

lorensr commented Jul 31, 2018 via email

@hwillson
Copy link
Member

Okay, thanks @lorensr. I'll add a few adjustments here (and will likely remove the subscriptions section completely since SubscriptionManager has been deprecated), then get this in place.

@theodorDiaconu I know you're doing a lot of interesting things with regards to Meteor + Apollo integration. Once we have this section cleaned up a bit, if you're interested in adding a reference to your https://github.com/cult-of-coders/apollo project, let me know. Thanks!

@hwillson hwillson self-assigned this Jul 31, 2018
@theodorDiaconu
Copy link

@hwillson can you define what kind of reference you mean ?

@hwillson
Copy link
Member

hwillson commented Aug 1, 2018

@theodorDiaconu I just meant that in the Meteor + Apollo section, we're mentioning the apollo package and swydo:ddp-apollo. If you would like us to add a link to your https://github.com/cult-of-coders/apollo project as well, let us know.

@lorensr
Copy link
Contributor Author

lorensr commented Aug 3, 2018

@hwillson v3 of meteor/apollo has been published

@tab00
Copy link

tab00 commented Aug 14, 2018

Good work with the new content so far, guys. It has been much needed.

You can remove the instructions to install graphql-playground as it's now automatically installed. You can simply load it in the browser with /graphql path.

Please update the Subscriptions section to show new syntax and examples (that work) with WebSocketLink and without SubscriptionManager, or SubscriptionServer, as I've been having trouble getting it working and have been looking around.

Thank you.

@tab00
Copy link

tab00 commented Aug 14, 2018

I think I've worked out how to do Subscriptions client-side. Feel free to use this to replace the old code.

import ApolloClient from 'apollo-client'
import { ApolloLink } from 'apollo-link'
import { MeteorAccountsLink } from 'meteor/apollo'
import { HttpLink } from 'apollo-link-http'
import { WebSocketLink } from 'apollo-link-ws'
import { InMemoryCache } from 'apollo-cache-inmemory'

const apolloClient = new ApolloClient({
  link: ApolloLink.split( // split based on operation type
    ({ query }) => {
      import { getMainDefinition } from 'apollo-utilities'
      const { kind, operation } = getMainDefinition(query)
      return kind === 'OperationDefinition' && operation === 'subscription'
    },
    new WebSocketLink({
      uri: `ws://localhost:3000/subscriptions`,
      options: { reconnect: true }
    }),
    ApolloLink.from([
      new MeteorAccountsLink(),
      new HttpLink({ uri: '/graphql' })
    ]),
  ),
  cache: new InMemoryCache()
})


import { ApolloProvider, Subscription } from "react-apollo"
import gql from 'graphql-tag'

return (
  <React.StrictMode>
    <ApolloProvider client={apolloClient}>
      <Subscription
        subscription={gql`
              subscription onCommentAdded($repoFullName: String!){
                commentAdded(repoFullName: $repoFullName){
                  id
                  content
                }
              }`}

        variables={{ repoFullName: "full name" }}
      >
        {({ data, loading, error }) => {
          if (loading) return null
          if (error) console.log(`Subscription error: ${JSON.stringify(error)}`)
          else console.log(`New data from subscription: ${JSON.stringify(data)}`)
          return JSON.stringify(data)
        }}
      </Subscription>
    </ApolloProvider>
  </React.StrictMode>
)

@tab00
Copy link

tab00 commented Aug 17, 2018

Can we see some working code for using the built-in subscription server in Apollo Server? I've been having some trouble. See my code at apollographql/apollo-server#1537

Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @lorensr!

@hwillson
Copy link
Member

I'm going to merge this as is. @tab00, any chance you'd like to create a separate PR with the subscription section changes? Thanks all!

@hwillson hwillson merged commit cf5c440 into master Aug 17, 2018
@hwillson hwillson deleted the lorensr/update-meteor-docs branch August 17, 2018 09:46
@lorensr lorensr mentioned this pull request Oct 5, 2018
8 tasks
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants