Giter VIP home page Giter VIP logo

meteor-graphql's Introduction

GraphQL Support for Meteor with Lokka

This is an alternative data layer for Meteor with GraphQL. Basically, it'll allow you to expose GraphQL schemas to the client.

Then you can use Lokka to interact with GraphQL schemas in the client side.

Usage

Add it your app with:

meteor add kadira:graphql

Then run your app with: meteor -p 3000

Then visit http://localhost:3000/graphql to see all the schemas available in your app.

Getting Started

Refer this guide to get started with GraphQL inside Meteor.

Features

  • Register multiple GraphQL schemas.
  • In Browser GraphQL IDE while development.
  • Seamless client side integration with Lokka.
  • React utilities.
  • Meteor based Authorization
  • Optimistic Updates support (via Lokka).
  • Client Side Caching (via Lokka).
  • Declarative Data Definition (via Lokka).

API

GraphQL Meteor intergration comes with few simple APIs. Let's explore them:

GraphQL.types [server only]

This holds all the types in GraphQL, where you can used to build GraphQL schemas. Check this schema for a sample usage.

GraphQL.registerSchema() [server only]

This API allows you to register a GraphQL schema with Meteor. Then you can use it on the client and inside the in-browser IDE.

const schema = new GraphQLSchema({
  query,
  mutation
});

GraphQL.registerSchema('Blog', schema);

Authorization

GraphQL uses Meteor methods as the transport layer. So, we can get the Meteor userId inside the GraphQL schema with the rootValue to the schema.

See how to use it inside a schema.

GraphQL.createLokkaClient() [client only]

This API allows you to create a Lokka client. Then you can use it to interact with your schema.

This will return a Lokka client with the version of 1.6.0.

BlogSchema = GraphQL.createLokkaClient('Blog');

Check this app on how to use Lokka in a real app.

GraphQL.bindData() [client only]

This is a general purpose React utility to bind data to a react component. Specially for a stateless component via props.

Let's say we've a component like this.

const CurrentTime = ({time, text}) => (
  <span>{text}: {time}</span>
);

We can bind the time to this component like this:

const onPropsChange = ((props, onData) => {
  // start the setInterval
  const handler = setInterval(() => {
    let time = (new Date()).toString();
    let text = "Current Time";

    // check props and do some logic
    if (props.timestamp) {
      time = Date.now();
      text = "Timestamp"
    }

    // send data like this
    //  if there's in an error, 
    //  send an Error object instead null
    onData(null, {time, text});
  }, 1000);

  // stop function to cleanup resources
  const stop = () => {
    clearInterval(handler);
  }

  // return the stop function which called when 
  // the component getting destroyed.
  return stop;
});

const Clock = GraphQL.bindData(onPropsChange)(CurrentTime);

Then we can render our clock like this:

ReactDOM.render((
    <div>
      <Clock /> 
      <Clock timestamp={true} />
    </div>
  ), document.body);

See how to use GraphQL.bindData with Lokka: https://goo.gl/M758pR

Loading Component

GraphQL.bindData will indentify the loading state of your component and it'll render a loading message to the UI. You can send a custom component like this:

const MyLoading = () => (
  <div>...+++...</div>
);
const Clock = GraphQL.bindData(onPropsChange)(CurrentTime, MyLoading);

Error Component

Just like the loading component, you can send a custom component to handle the error message. For that, do it like this:

const MyError = ({error}) => (
  <div>{error.message}</div>
);
const Clock = GraphQL.bindData(onPropsChange)(CurrentTime, null, MyError);

meteor-graphql's People

Contributors

adambrodzinski avatar arunoda avatar thani-sh 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

meteor-graphql's Issues

How to use `watchQuery' correctly ?

I tried to grab some fields' value from the Meteor User collection by using graphql and also using Loka's watchQuery(since I dont want to bind those values to any view component, so I'm not using graphQL.bindData) in client side to observe the collection with specify _id, but somehow the sever side always return null when i do Meteor.users.findOne({_id:userId}) (I guess is the asyc nature),

Add ability to enable GraphiQL in production

I'm working on several apps that are intended for developers to extend, and I find GraphiQL to be a great way of documenting an API and letting developers access it in production. Any chance we might have the ability to enable GraphiQL in production for sites where we'd like to allow external apps and find it to be a great documentation/test tool for developers using our platform?

Unless this is a bad idea for some reason, but it seems similar in spirit to the various REST documentation standards with the added benefit of easy experimentation.

Thanks.

Catch resolve errors and process there carefully

It's not a good idea to send server errors to the client. So, we need to catch errors in the resolve functions manually. This is the process we can do:

  • Catch errors and log them to the console
  • Create a new error as Internal Error rather the actual error.

Apollo ?

I'm considering using the GraphQL in my next application, but I'm not sure which way to go. Apollo seems to be in its beginnings with quite complex way of using. This project seems to have much cleaner API. I do not need reactivity, I'm fine with Mantra containers. Would you recommend me your project? If so, what are the disadvantages you see in comparison with Apollo? Thanks

npm peer requirements not installed

W20161121-22:02:30.949(2)? (STDERR) WARNING: npm peer requirements not installed:
W20161121-22:02:30.992(2)? (STDERR) - [email protected] installed, [email protected] needed
W20161121-22:02:30.993(2)? (STDERR) - [email protected] installed, [email protected] needed
W20161121-22:02:30.993(2)? (STDERR) - [email protected] installed, [email protected] needed
W20161121-22:02:30.993(2)? (STDERR) - [email protected] installed, [email protected] needed
W20161121-22:02:30.993(2)? (STDERR) - [email protected] installed, [email protected] needed
W20161121-22:02:30.994(2)? (STDERR) - [email protected] installed, [email protected] needed
W20161121-22:02:30.994(2)? (STDERR) - [email protected] installed, [email protected] needed
W20161121-22:02:30.994(2)? (STDERR) - [email protected] installed, [email protected] needed
W20161121-22:02:30.994(2)? (STDERR) - [email protected] installed, [email protected] needed
W20161121-22:02:30.994(2)? (STDERR) - [email protected] installed, [email protected] needed
W20161121-22:02:30.995(2)? (STDERR)
W20161121-22:02:30.995(2)? (STDERR) Read more about installing npm peer dependencies:
W20161121-22:02:30.995(2)? (STDERR) http://guide.meteor.com/using-packages.html#peer-npm-dependencies
W20161121-22:02:30.995(2)? (STDERR)

Hi! I have this warning message after added kadira:graphql to my project. Without this plugin I'm not have a problem.
Version: [email protected]

As repeat?

First step

$ meteor add kadira:graphql
$ meteor add react
$ meteor add react-meteor-data

Second step

$ meteor npm install

Third step

$ meteor

package:

"dependencies": {
"babel-runtime": "6.18.0",
"meteor-node-stubs": "~0.2.0",
"react": "^15.4.0",
"react-addons-pure-render-mixin": "^15.4.0",
"react-addons-create-fragment": "^15.4.0",
"react-addons-css-transition-group": "^15.4.0",
"react-addons-linked-state-mixin": "^15.4.0",
"react-addons-perf": "^15.4.0",
"react-addons-test-utils": "^15.4.0",
"react-addons-transition-group": "^15.4.0",
"react-addons-update": "^15.4.0",
"react-dom": "^15.4.0"
}

Two Questions

  • Is this package production ready?
  • Are there any plans to introduce reactivity?

One Server, Multiple Clients

What's attracting me to GraphQL for a suite of Meteor apps is the one GraphQL server with multiple clients, as per this diagram on learngraphql.com
screen shot 2016-03-20 at 11 29 25

I'm not sure how this is meant to be achieved with Meteor though. Do I have a GraphQL server and have to expose HTTP end points manually? Do I connect via DDP? What's the suggested solution here.

Presumably the GraphQL Server in this case wouldn't even need to be a Meteor application, I could just have Meteor clients that are making calls to it, right?

Support server to server query

Thanks kadirahq's good work.

Just like we can do server to server ddp publish / subscribe. Is it possible to export server side lokka client for query from other Graphql server / meteor-graphql server ?

SyntaxError: Unexpected end of input

I'm getting a weird error now and i'm not sure what's going on.... perhaps my packages are corrupt? All of a sudden none of my Meteor GraphQL apps are working. This is in a new test app after accessing the system info query:

W20160110-23:56:59.405(-5)? (STDERR) SyntaxError: Unexpected end of input
W20160110-23:56:59.406(-5)? (STDERR)     at Object.parse (native)
W20160110-23:56:59.406(-5)? (STDERR)     at _GraphQL$types (server/ide.js:27:34)
W20160110-23:56:59.406(-5)? (STDERR)     at doCall (packages/meteorhacks_picker/packages/meteorhacks_picker.js:106:1)

Update, I also removed my ~/.meteor folder and re-installed meteor. Booted up a fresh empty app and am getting the same error.

{
  sysInfo {
    hostname
    memory
    uptime
  }
}

http://localhost:3000/graphql/ide?schema=SysInfo

screen shot 2016-01-11 at 12 17 39 am

screen shot 2016-01-11 at 12 20 37 am

Real-time GraphQL Publications

First, great work on this and thank you for building and sharing it!

I had a quick question about how this particular feature will be implemented: in meteor-any-db, on mutations you call AnyDb.refresh with the possibly-refreshed publication name and a filter function, which I can imagine gets complicated when we have a huge dependency tree of mutations and relevant publications that could be updated. In the context of this article on GraphQL subscriptions, it seems like this is the "live queries" approach (please let me know if I'm incorrect about that).

Can you elaborate more on what an events-based subscription would look like based what you said in your article here:

Real-time support will be based on application-specific events. So, we could plug in any database with a queue like Kafka (or even Redis) to make our apps real-time.

It feels like GraphQL Meteor publications are the holy grail of real-time APIs, so naturally I'm very curious as to how and when this will come to be. Thanks again @arunoda!

Error: 'return' outside of function

Hey,

After installing kadira:graphql using meteor add kadira:graphql and starting the Meteor server, I get these error messages:

=> Started proxy.                             
=> Started MongoDB.                           
=> Errors prevented startup:                  

   While processing files with ecmascript (for target os.osx.x86_64):
   packages/kadira:graphql/server/ide.js:3:2: /packages/kadira:graphql/server/ide.js: 'return' outside of function (3:2)
   packages/kadira:graphql/server/sample_schema.js:2:2: /packages/kadira:graphql/server/sample_schema.js: 'return' outside of function (2:2)

I'm using Meteor version Meteor 1.3-modules-beta.5

Anyone else experiencing the same thing? If I uninstall the package, it works again.

Custom api prefix

Hi @arunoda
i using your package to create apis for client products.
You package just support only meteor, but i found a tweak to call from client products like

import HttpTransport from 'lokka-transport-http';
const transport = new HttpTransport('http://localhost:3003/graphql/ide?schema=SysInfo');
transport.send(`
  {
    sysInfo {
      hostname
    }
  }
`).then(response => {
    console.log(JSON.stringify(response, null, 2));
});

so can you publish one more entry point for other client apps? and support ability to change route path ! like /api

watchQuery doesn't work after page refresh

I've used watchQuery with parameters to fetch a user, its payload dose fetch the user at the first load, but I refresh the page and call the watchQuery with the same parameters, the watchQuery's payload return undefined. Any reason why this happen? thanks

Use graphql from another meteor server

I have a meteor server that consume data from another meteor server using graphql.
The Master meteor server has the schema defined,
How can the slave fetch the data using lokka? I dont see a way to define a URL.
Maybe I should use lokka npm directly?

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.