Giter VIP home page Giter VIP logo

meteor-integration's Introduction

meteor-integration's People

Contributors

barbatus avatar benjamn avatar comus avatar guyavraham avatar jangerhofer avatar jasonphillips avatar kokjinsam avatar lorensr avatar nicolaslopezj avatar siyfion avatar timbrandin avatar todda00 avatar xavxyz avatar zvictor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

meteor-integration's Issues

Add TypeScript typings for 'meteor/apollo'

Are there any TypeScript type definitions available for meteor-integration to overcome the TypeScript TS2307:Cannot find module 'meteor/apollo'. warning message? Any work-arounds? Thanks!

Apollo Optics

Is there a way to use Apollo Optics with this package, or would we need to integrate Apollo manually to apply OpticsAgent as middleware and set opticsContext?

userId caching

I was planning on only using lru-cache, but @stubailo reminded me with talk of observe that we're in Meteorland, not just nodeland. Shouldn't we first check whether Meteor has the current user's login info? If the client has a DDP connection open to the same app server as the app server that the GraphQL request comes to (which should happen if you have sticky routing like Galaxy), the info should be in memory in the same node process, right? Is there a Meteor lookup table of connection/session id -> connection object? In which case we could use the userId on the connection object. So the client would send two headers, one with Meteor.connection._lastSessionId, and one with the login token. It would try to look up the session, and if fails, use the lru-cache.

/graphql responding with 503 after 4 min

Just released meteor/[email protected], but I think there's a bug in it. When I pointed meteor-starter-kit at meteor-integration locally, it worked, but after releasing and pointing at the atmosphere version, I started getting the bad behavior. It continues even when I switch back to local.

image

image

git clone [email protected]:apollographql/meteor-starter-kit.git
git checkout 0.3.0-wip
npm install
meteor

Custom NetworkInterface for meteorClientConfig

Hi,

I'm currently trying to make PersistedQueryNetworkInterface from https://github.com/apollographql/persistgraphql work with this package, but as mail-client.js uses createNetworkInterface from the apollo-client package, there is no clean way to use another networkInterface.

Why not simply set by hand the NetworkInterface, without using meteorClientConfig ?

Well because meteorClientConfig is very convenient as it adds a middleware to support Meteor User Account, and I don't want to simply copy/paste this middleware into my code.

Do you think such a feature could be useful ? Would you be interested in a PR that enable the user to use a custom NetworkInterface inside meteorClientConfig ?

Does optics code break context?

reported by @davidboom95

Hi, it seems this code breaks the meteor context, it should pass context.userId and context.user, when I try to reverse changes, context is still undefined. I tried meteor reset, and re-install apollo-server but it does not work

#47 (comment)

Cache size?

For v1, only caching and providing user id as context, not whole user doc.

How many MB default cache size? 6.6k users per MB. 512 MB RAM in smallest Galaxy container.

Cache key is 44 characters. At 2B/character, that's 88B/key. The value is [id, expires]. The attributes are:

  • 17 characters per Meteor id = 34 B
  • Looks like Dates are Numbers, which are 8B
  • How much overhead does a 2-elem array and the cache itself have? Let's say 20 B.

88 + 34 + 8 + 20 = 150 B per entry.

External .graphql files

Can someone give a snippet example of how to store the graphql queries externally or separately in a file (.graphql or whatever extension)? And from which directory to import them into the meteor app?

websocket connection failed

When testing the test case, i have been noticing following warning since v0.3.1.
WebSocket connection to 'ws://localhost:3000/sockjs/893/7ccqcy1c/websocket' failed: WebSocket is closed before the connection is established.

image

Installation / version problem

Round 1

Following the instructions here, I added the Apollo packages to my Meteor (1.4.3.1) app with these commands:

meteor add apollo
meteor npm install --save apollo-client graphql-server-express express graphql graphql-tools body-parser

However, this resulted in an invalid combination of versions:

WARNING: npm peer requirements (for apollo) not installed:
  - apollo-server@^0.1.1 not installed.
  - http-proxy-middleware@^0.15.0 not installed.

This is caused by the fact that for some reason, I got Apollo v0.0.1, which depends on a completely different set of NPM packages, not the one I installed (following the instructions).

Round 2

Since according to the relevant Atmosphere page, the latest version of the Apollo Meteor package is 0.3.1, I updated it manually:

meteor add [email protected]

With this, it got closer to working, but still not there. Now I get these messages:

WARNING: npm peer requirements (for apollo) not installed:
  - [email protected] installed, graphql-server-express@^0.5.0 needed
  - [email protected] installed, graphql@^0.7.0 || ^0.8.0 needed
  - [email protected] installed, graphql-tools@^0.9.0 needed

So, now the peer dependencies are there, but it looks like the Meteor package is lagging behind the NPM versions. Is there a chance that it will be updated soon?

In the meantime, can I ignore these warnings, and just use the package anyway?
(I am new to Apollo, so I would like to avoid having to figure out whether any problems I hit originate in version incompatibilities...)

Thanks.

SyntaxError: Use of const in strict mode

I get this error when adding graphql to my Meteor server code:

/.../...app/.meteor/local/build/programs/server/packages/modules.js:55907
W20160929-19:06:56.052(3)? (STDERR) const graphql_1 = require('graphql');
W20160929-19:06:56.053(3)? (STDERR) ^^^^^
W20160929-19:06:56.054(3)? (STDERR) SyntaxError: Use of const in strict mode.

This is what I used to install Apollo:

meteor add apollo
meteor npm install --save apollo-client apollo-server express graphql graphql-tools body-parser

This is the code I've added:

import { createApolloServer } from 'meteor/apollo';
import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools';

const typeDefs = [`
type Email {
  address: String
  verified: Boolean
}
type User {
  emails: [Email]
  username: String
  randomString: String
}
type Query {
  user(id: String!): User
}
schema {
  query: Query
}
`];

const resolvers = {
  Query: {
    async user(root, args, context) {
      // Only return the current user, for security
      if (context.userId === args.id) {
        return await Meteor.users.findOne(context.userId);
      }
    },
  },
  User: {
    emails: ({emails}) => emails,
    randomString: () => Meteor.Random.id(),
  }
}

const schema = makeExecutableSchema({
  typeDefs,
  resolvers
});

createApolloServer({
    schema,
});

I'm on Meteor 1.3.3.1.

CORS issue

Hi

How do i add CORS to the apollo instance ?

I'v been working in test-apps and now i want to move my Apollo-Express to Meteor/Apollo. Im trying to obtain the "app" or "graphqlServer" instance to call the .use() method. Maybe is it ready ? or im confused...

Thanks

Default port?

Currently 4000. From @timbrandin:

image

Should we set the default port to 80 and just note to not put an asset or route at /graphql?

We should at least support passing 80 as a config param.

Allow using Apollo with Meteor server side only

My app is written in Blaze and I don't want to use Apollo client right now. I am interested in connecting from a React Native app to Apollo on my Meteor server however.

I removed apollo-client as an npm package from my Meteor app and I now get the following error warning in the browser console:

check-npm-versions.js:53 WARNING: npm peer requirements (for apollo) not installed:
 - apollo-client@^0.4.0 || ^0.3.0 not installed.

Read more about installing npm peer dependencies:
  http://guide.meteor.com/using-packages.html#peer-npm-dependencies
checkNpmVersions @ check-npm-versions.js:53
modules-runtime.js?hash=ab7e8d3โ€ฆ:470 Uncaught Error: Cannot find module 'apollo-client'(โ€ฆ)

I don't if this has any major effects, but it would be nice to be able to use Apollo with Meteor server side only.

Package ready

When is the ETA in publishing this to (Atmosphere) Meteor?
Looks quite solid to me already.

"Error: Meteor code must always run within a Fiber..." in Mutations only

Let's say we've got the following very simple GraphQL schema:

type ContentBlock {
  _id: String
  content: String
}
type RootQuery {
  contentBlock(id: String!): ContentBlock
}
type RootMutation {
  upsertContentBlock(id: String!, content: String!): ContentBlock
}
schema {
  query: RootQuery
  mutation: RootMutation
}

At first let's connect our React component with:

function mapQueriesToProps({ownProps: {contentId}}) {
  return {
    data: {
      query: gql`
        query getContent ($id: String!) {
          contentBlock(id: $id) {
            _id
            content
          }
        }
      `,
      variables: {id: contentId}
    }
  }
}

Resolvers:

{
  RootQuery: {
    contentBlock(root, args, context) {
      try {
        return context.connectors.ContentBlock.findById(args.id);
      } catch (err) {
        console.log(err.stack);
        throw err;
      }
    },
  },
  RootMutation: {
    upsertContentBlock(root, args, context) {
      try {
        return context.connectors.ContentBlock.upsert(args.id, args.content);
      } catch (err) {
        console.log(err.stack);
        throw err;
      }
    },
  },
};

ContentBlock connector:

class ContentBlockConnector {
  findById(id) {
    return ContentBlocks.findOne(id);
  }
  upsert(id, content) {
    const result = ContentBlocks.upsert({_id: id}, {
      $set: {content}
    });
    return ContentBlocks.findOne(id);
  }
}

Note: ContentBlocks is a Mongo.Collection.
So far everything works fine. The connected React component successfully fetches content by contentId. Now let's try to add the mutation and connect our component with:

function mapMutationsToProps({ownProps: {contentId}}) {
  return {
    saveContent: (content) => {
      return {
        mutation: gql`
        mutation updateContent($id: String!, $content: String!) {
          upsertContentBlock(id: $id, content: $content) {
            _id
            content
          }
        }
      `,
        variables: {
          id: contentId,
          content,
        },
      };
    },
  };
}

Now when we call this.props.mutations.saveContent(content); within our react component, we get the following Error on the server: Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.

Now let's change our mutation resolver to do the exact same thing the query resolver does:

{
  RootQuery: {
    contentBlock(root, args, context) {
      try {
        return context.connectors.ContentBlock.findById(args.id);
      } catch (err) {
        console.log(err.stack);
        throw err;
      }
    },
  },
  RootMutation: {
    upsertContentBlock(root, args, context) {
      try {
        return context.connectors.ContentBlock.findById(args.id);
      } catch (err) {
        console.log(err.stack);
        throw err;
      }
    },
  },
};

Calling this.props.mutations.saveContent(content); now still yields an Error: Can't wait without a fiber.

Now try to use Meteor.bindEnvironment to wrap the resolver (note that the Meteor package already does WebApp.connectHandlers.use(Meteor.bindEnvironment(graphQLServer));) :

{
  ...
  RootMutation: {
    upsertContentBlock: Meteor.bindEnvironment(function (root, args, context) {
      ...
    }),
  },
}

No more error, but inspecting the GraphQLResult from this.props.mutations.saveContent(content).then(GraphQLResult => ...) shows that its data property is {upsertContentBlock: null, __typename: "RootMutation"} where upsertContentBlock shouldn't be null because the resolver returns an object.

Is anyone experiencing the same problems when using Apollo with Meteor? Can someone explain what's going on there and why calling methods on Mongo.Collections work with query resolvers and don't work (as expected) with mutation resolvers?

Thanks in advance.

Versions

{
  "apollo-client": "^0.3.24",
  "apollo-server": "^0.1.5",
  "react": "^15.1.0",
  "react-apollo": "^0.3.13",
}

Handling log in/log out

I currently have a currentUser query in my global app container that loads the current user, and I'm handling user accounts through the accounts-ui package.

The problem is that the Apollo query doesn't know it needs to re-run when the Meteor user's logged in/logged out state changes.

So the flow looks something like this:

  1. Load app, run query for currentUser which returns nothing because no user is logged in.
  2. User logs in.
  3. ???
  4. Rerun query for currentUser to get the current user profile.

As you can see things break down at step 3. What's the best way of telling the query to rerun? One solution would be calling refetch() in an autorun block containing Meteor.user()?

Another issue related to the way I've currently set things up is that refetching the currentUser query would force my entire app to reload:

const AppContainer = (props, context) => {

  const {loading, refetch, currentUser, categories} = props.data;
  
  return <Telescope.components.App
    ready={!loading}
    currentUser={currentUser}
    categories={categories}
    events={Events}
    {...props}
  />;
};

Is there a way to rerun the query without setting loading to false? Or a better pattern for setting up your app container?

Remove mongo / minimongo from client?

Hey,
One question thats bothering me: Is it possible to completely remove mongo and minimongo from the client?

This package uses accounts-base which has a dependency to mongo, so I guess thats the problem here right?

Account impersonation & Apollo...

So I've been using a form of account impersonation for my admin team to manage other people's accounts and/or data without knowing their passwords, etc.

Loosely based on https://dweldon.silvrback.com/impersonating-a-user I use, @gwendall's https://github.com/gwendall/meteor-impersonate

Would it be possible to somehow integrate these two packages, so that the impersonation isn't "lost" in the Apollo data endpoints.

Perhaps @lorensr will have some words of wisdom!? ๐Ÿ‘

graphiql broken with last apollo version

the latest apollo version 0.1.2 seems to be broken, localhost:3000/graphiql fails with:

TypeError: undefined is not an object (evaluating 't.toString')

both with Meteor 1.4.1.1 and 1.4.1.2

version 0.1.1 runs fine.

Demystifying Meteor โ†”๏ธ Apollo integration with a code tour

Current state of the art

We have docs, we have starter kit, but I feel like many folks in the Meteor world still seem to have troubles to grasp how it works together.

I'm not that much on the forums, but I've seen that in my local meetup (Paris, FR) & listening to Transmission Podcast.

What if we take people by the hand

I've created a code tour to demystify that:

Some gif to show how to take the codetour, just click on it

Here is how to have a look at it directly: https://www.codetours.xyz/tour/xavcz/meteor-apollo-codetour

To this repo watchers, contributors & anyone interested in

I would love your feedback on it to make it clearer how to spread the word that building something with Meteor & Apollo is not obscure at all!
โžก๏ธ Codetour: https://www.codetours.xyz/tour/xavcz/meteor-apollo-codetour
โžก๏ธ Repo to correct my fragile English syntax and enhance the Markdown formatting: https://github.com/xavcz/meteor-apollo-codetour ๐Ÿ˜„

Allow meteorClientConfig to be used on the server

I'm building a isomorphic app that does server side rendering, wen I try to use the apollo client on the server side like:

import ApolloClient from 'apollo-client';
import {meteorClientConfig} from 'meteor/apollo';

const client = new ApolloClient(meteorClientConfig());

It fails, server command line log shows that meteorClientConfig is not a function.

Wen I put a condition

var client = {};
if(Meteor.isClient){
    client = new ApolloClient(meteorClientConfig());
    console.log(client);
}

It works but that means the server cant access the db, only the browser.

ps: originally posted here apollographql/apollo-client#1006

Propose to simplify client configuration

With the new apollo-client update, we have to add queryTransformer and dataIdFromObject when initializing ApolloClient and I feel like there are lots changes happening. I think it would be better if these APIs don't surface to the user. I created my own meteor-apollo integration for testing. Check it out here.

In my repo, user will just do

const client = configureGraphQLClient();

and an ApolloClient is created.

"Can't wait without a fiber" error both in resolver and mutations

root schema and resolver:

const rootSchema = `
   type RootQuery {
    user: User    
   ...
    allFeedbacks: [Feedback]
   }

   schema {
    query: RootQuery
  }
`


RootQuery: {
...

    async allFeedbacks(root, args, context) {
      const allFeedbacks = DB.Feedback.find({patientId: {$exists: 1}}).fetch()
      return await allFeedbacks
    },
...
}

feedback.js

export const schema = `
  type Feedback {
    _id: String
    patient: User
    opinion: String
    reply: String
  }
`;

export const resolvers = {
  Feedback: {
    _id  : ({_id}) => _id,
    patient: async ({patientId}) => {
      return await Meteor.users.findOne({_id:patientId})
    },
    opinion: ({opinion}) => opinion,
    reply: ({reply}) => reply,
  }
};

query in graphiql:
{ allFeedbacks { patient { username } _id opinion reply } }

Got result:

{
"data": {
"allFeedbacks": [
{
"patient": null,
"_id": "nyNP9wh9D5qmZixbn",
"opinion": "tesst",
"reply": "testst"
},
{
"patient": null,
"_id": "WgSoCgTGhHeZasFGQ",
"opinion": "tesst",
"reply": "testst"
},

...

{
"message": "Can't wait without a fiber",
"locations": [
{
"line": 4,
"column": 5
}
]
},
}

It's strange when i test , the resolver could console log PatientId, Meteor, Meteor.users, But can't get the fetched data. I guess the problem is on async, but where is the problem?

Had checked sample repos, followed their pattern but no luck.

Suggestion: Use the DDP connection as a network interface

Meteor supplies us with a great websocket implementation with authentication, retries and more. We could simply leverage this power by making a network interface that calls a DDP method:

Client

// ddp-network-interface.js
class DDPNetworkInterface {
    constructor({
        connection,
        noRetry = true,
        method = '/graphql' } = {}
    ) {
        this.connection = connection;
        this.noRetry = noRetry;
        this.method = method;
    }

    query(request) {
        return new Promise((resolve, reject) => {
            this.connection.apply(this.method, [request], { noRetry: this.noRetry }, (err, data) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(data);
                }
            });
        });
    }
}

export { DDPNetworkInterface };
// client.js
import ApolloClient from 'apollo-client';
import { DDPNetworkInterface } from './ddp-network-interface';

export const client = new ApolloClient ({
  networkInterface: new DDPNetworkInterface({ connection: Meteor.connection })
})

Server

import { schema } from './schema';
import { runQuery } from 'apollo-server';

export const methods = {
    '/graphql'({ query, variables }) {
        this.unblock();

        const { userId } = this;

        return runQuery({
            schema,
            query,
            variables,
            context: {
                userId
            }
        }).await();
    }
};

Meteor.methods(methods);

I'm testing this for our own app and it's seems to work perfectly so far.

If people are interested in this I would love to make a PR for it. What do you think @lorensr?

Update to latest apollo-client version

First of all: thanks for providing this integration for Meteor.

When using the latest meteor-integration from Atmosphere I get the warning: [email protected] installed, apollo-client@^0.5.0 needed. Can that be safely ignored?

If not, am I constrained to v0.5.0 of apollo-client with Meteor (at least when I want to use this integration)? When will there be an update that supports the latest versions?

Thank you so much for your efforts!

Update (Just for the sake of completeness)

I get the following warnings on the server side:

WARNING: npm peer requirements (for apollo) not installed:
 [email protected] installed, graphql-server-express@^0.4.3 needed
 [email protected] installed, graphql@^0.7.0 || ^0.8.0 needed
 [email protected] installed, graphql-tools@^0.8.0 needed

Update to apollo-server 0.2

Hi, this no longer works with Apollo server 2.0+

I managed to solve most of the issues, but I have no idea how to approach the filling of context with meteor users information, since server 2.0 now uses context as a simple object.

User Accounts middleware is not working on IE11

I have this code for my mutation. Everything is working perfectly everywhere but in IE11. It throws an error because there in no context.

      Mutation: {
        insertBusinessIdea (_, {name}, context) {

          if (!context.userId) {
            throw new Meteor.Error('User must be logged in to create a new Business Idea') //IE11 not working
          }


          const businessIdeaId = BusinessIdeas.insert({
            name: name,
            createdBy: context.userId,
            createdAt: new Date()
          })
          return BusinessIdeas.findOne(businessIdeaId)
        }

Calling Meteor.logout() doesn't do anything.

When calling Meteor.logout(), the context.userId on the server side should be set to undefined. Instead, it is still set as the id for the previously logged in user. If I restart the server process, the cached userId is cleared and all is well again.

Peer dependency - unnecessary warnings

I'm getting WARNING: npm peer requirements (for apollo) not installed: [email protected] installed, graphql@^0.6.2 needed. Everything seems to work fine, so that dependency should probably be updated to add 0.7.x.

Also there is a dependency on 'apollo-client': '^0.4.11', but it seems to work fine with client 0.3.x. I haven't tested extensively, but I don't see anything that touches API changes for 0.4.

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.