Git Product home page Git Product logo

Comments (17)

stubailo avatar stubailo commented on March 29, 2024 1

Also, would be great if you would hide all NPM packages into the Meteor package so no Npm install would be necessary.

Definitely DO NOT do this. The whole idea is that you can update the NPM package as necessary without waiting for the Meteor package maintainer to get around to updating their wrapper.

from apollo-server.

stubailo avatar stubailo commented on March 29, 2024

Where are you putting the async await functions? The npm package is pre-built before publishing to NPM, so it's not really a problem with this package.

BTW @lorensr was thinking of working on a Meteor integration package as well!

from apollo-server.

tomitrescak avatar tomitrescak commented on March 29, 2024

For example in following code it says: "Can't wait without fiber" on line with Meteor.user retrieval

graphQLServer.use('/graphql', apolloServer(async(req) => {
    let user = null; 
    if (req.headers.authorization) {
      const token = req.headers.authorization;
      check(token, String);
      const hashedToken = Accounts._hashLoginToken(token);
      user = await Meteor.users.findOne({
        "services.resume.loginTokens.hashedToken": hashedToken
      });
    }

    return {
      graphiql: true,
      pretty: true,
      schema,
      resolvers,
      context: {
        // The current user will now be available on context.user in all resolvers
        user,
      }
    };
  }));

from apollo-server.

stubailo avatar stubailo commented on March 29, 2024

It works fine here: https://github.com/apollostack/meteor-starter-kit/blob/master/server/main.js

I guess you put this code into an NPM package, and it doesn't work anymore?

The async fiber support relies on Meteor's Promise polyfill, so you should make sure you aren't including any other promise polyfills in your NPM package.

from apollo-server.

tomitrescak avatar tomitrescak commented on March 29, 2024

The previous code works flawlessly in Meteor, but when built as Npm package it fails.

from apollo-server.

tomitrescak avatar tomitrescak commented on March 29, 2024

Ha! The Meteor polyfill will be the problem ... would you be able to point me out how can I use it with babel?

from apollo-server.

stubailo avatar stubailo commented on March 29, 2024

You could just not use async/await in your package btw - that would be the easiest choice. Also, I'd suggest using an Atmosphere package instead of NPM for the short term, until Meteor 1.5 makes it possible for NPM packages to take advantage of more Meteor features.

from apollo-server.

tomitrescak avatar tomitrescak commented on March 29, 2024

I'll try with atmosphere package. Good idea.

I cannot work without async/await as all update / insert queries fail complaining that they do not run in Meteor Fiber.

from apollo-server.

lorensr avatar lorensr commented on March 29, 2024

@tomitrescak Hi Tomas, here's the shell I made for the atmosphere package:

https://github.com/apollostack/meteor-integration

I'd be interested to hear your thoughts on the API:

apollographql/meteor-integration#2

And would be happy to work on PRs with you if you'd like to combine efforts 😄

from apollo-server.

tomitrescak avatar tomitrescak commented on March 29, 2024

@lorensr looks great! I'll give it a go. My effort is not going very well. Just created the meteor package but am still getting "Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment." error.

Wht I miss in the package is the possibility to incrementally add resolvers. In a complex application with 50+ queries it would be great to have a possibility to split queries and mutations by modules. That is one of the things I tried to implement, but am hitting the wall with async.

I tried to look at how you've done it, but looks like you currently have only a shell, no implementation.

So, when you start to implement "useMeteorAccounts" you probably will run into very same issue. There the error is "Cannot await when not in Fiber".

from apollo-server.

tomitrescak avatar tomitrescak commented on March 29, 2024

Also, would be great if you would hide all NPM packages into the Meteor package so no Npm install would be necessary.

My repo is here:

https://github.com/tomitrescak/apollo-redux-tools.git

from apollo-server.

stubailo avatar stubailo commented on March 29, 2024

Wht I miss in the package is the possibility to incrementally add resolvers.

You can use _.merge to combine as many resolver objects as you want.

from apollo-server.

tomitrescak avatar tomitrescak commented on March 29, 2024

@stubailo ... just bumped into Meteor recommendation to NOT do that ;)

from apollo-server.

stubailo avatar stubailo commented on March 29, 2024

What do you mean?

from apollo-server.

tomitrescak avatar tomitrescak commented on March 29, 2024

I confirmed what you just said. I was checking the Meteor recommendations for package authors.

from apollo-server.

tomitrescak avatar tomitrescak commented on March 29, 2024

The moment I moved all npm dependencies form package to root level the async problem disappeared, yet another one appeared as "context" is always null in my queries.

This is how I init the server:

const res = {
      graphiql: true,
      pretty: true,
      schema,
      resolvers,
      context: {
        // The current user will now be available on context.user in all resolvers
        user,
      }
    };

I'm sure that user is filled in. Then in my mutation:

addComment(root: any, { postId, comment }: any, context: any) {
    console.log("adding: " + context);
    const id = Comments.insert({ postId: postId, text: comment, createdAt: new Date().getTime(), author: context.user._id });
    return Posts.findOne(id);
  }

The context is null. Do you have any idea why this could happen?

[EDIT] Nevermind ... all solved.

from apollo-server.

tomitrescak avatar tomitrescak commented on March 29, 2024

@lorensr I like the API, most of it is there. I'll try to do the PR tomorrow with what I've done. You'll see how much of it is trash.

from apollo-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.