All Projects → matteodem → graphqlizer

matteodem / graphqlizer

Licence: AGPL-3.0 license
Make your meteor mongo collections accessible over a graphql endpoint

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to graphqlizer

Future Web
Starter kit to create PWA with cutting edge technologies
Stars: ✭ 38 (+2.7%)
Mutual labels:  apollo, meteor
Vue Meteor
🌠 Vue first-class integration in Meteor
Stars: ✭ 893 (+2313.51%)
Mutual labels:  apollo, meteor
meteor-apollo2
An example showing how to use Apollo 2.0 with GraphQL server + subscriptions
Stars: ✭ 20 (-45.95%)
Mutual labels:  apollo, meteor
Meteor Apollo Accounts
Meteor accounts in GraphQL
Stars: ✭ 145 (+291.89%)
Mutual labels:  apollo, meteor
Meteor Apollo Starter Kit
Meteor, Apollo, React, PWA, Styled-Components boilerplate
Stars: ✭ 91 (+145.95%)
Mutual labels:  apollo, meteor
Blaze Apollo
Blaze integration for the Apollo Client
Stars: ✭ 56 (+51.35%)
Mutual labels:  apollo, meteor
Pup
The Ultimate Boilerplate for Products.
Stars: ✭ 563 (+1421.62%)
Mutual labels:  apollo, meteor
Apollo
Meteor & Apollo integration
Stars: ✭ 87 (+135.14%)
Mutual labels:  apollo, meteor
Meteor Integration
🚀 meteor add apollo
Stars: ✭ 107 (+189.19%)
Mutual labels:  apollo, meteor
Ddp Apollo
DDP link for Apollo with GraphQL Subscriptions support
Stars: ✭ 163 (+340.54%)
Mutual labels:  apollo, meteor
meteor-search
🔍 SPIKE of full-text search in MongoDB using Meteor
Stars: ✭ 40 (+8.11%)
Mutual labels:  meteor
NASSP
Project Apollo - NASSP
Stars: ✭ 110 (+197.3%)
Mutual labels:  apollo
node-on-fhir
Tech stack for building MACRA and 21st Century Cures compliant webapps.
Stars: ✭ 75 (+102.7%)
Mutual labels:  meteor
rogue.js
The "nearly invisible" way to server-render React applications
Stars: ✭ 1,914 (+5072.97%)
Mutual labels:  apollo
erxes-widgets-api
Deprecated: Repo is now integrated with erxes-api
Stars: ✭ 22 (-40.54%)
Mutual labels:  apollo
Block-Farm
A farming game built upon Ethereum platform.
Stars: ✭ 60 (+62.16%)
Mutual labels:  meteor
RxApolloClient
RxSwift extensions for Apollo Client
Stars: ✭ 46 (+24.32%)
Mutual labels:  apollo
alda
A boilerplate for React isomorphic aplication with Material Design
Stars: ✭ 16 (-56.76%)
Mutual labels:  apollo
redwood
The App Framework for Startups
Stars: ✭ 15,079 (+40654.05%)
Mutual labels:  apollo
kernel xiaomi sm8250
CLO Rebased kernel for Xiaomi SM8250 series devices updated to CAF tag LA.UM.9.12.r1-14700-SMxx50 with AOSP android-4.19-stable merged.
Stars: ✭ 111 (+200%)
Mutual labels:  apollo

graphqlizer

Build Status Code Climate Maintainability Get help on Codementor

Make your meteor mongo collections accessible over a graphql endpoint.

  • Generates simple type definitions + resolvers
  • Uses check and SimpleSchema to validate arguments
  • Great for prototyping and beyond

Basic Code Example

This package does not fully abstract GraphQL, so be sure to learn about it so that you have the needed vocabulary and knowledge to profit from this package. The GraphQL site has a cool text based introduction and if you're a visual kind of person like me, you can check out my introduction screencast.

If you want a simple usage example check out the test app.

How to install

# Install npm packages
meteor npm install --save apollo-client graphql-server-express express graphql graphql-tools body-parser
# Install meteor packages
meteor add apollo aldeed:simple-schema easy:graphqlizer

How to use

Graphqlizer uses SimpleSchema to generate the resolvers and type definitions. The most basic configuration requires you to pass the mongo collection and a name (TitleCase) to identify your data.

import { crud } from 'meteor/easy:graphqlizer'
import { CarCollection } from '{...}'

const alienSchema = crud('Car', CarCollection)
// or with a custom schema
const otherAlienSchema = crud('Car', CarCollection, CustomCarSimpleSchema)

You can optionally specify a custom schema as the 3rd argument. Graphqlizer uses the simple schema configuration to infer the graphql type fields (Int, Float etc) and if it's optional or required (!).

To actually have access to your data you have to use the generateTypeDefsAndResolvers function to generate the final typeDefs and resolvers to create the GraphQL schema.

import { crud, generateTypeDefsAndResolvers } from 'meteor/easy:graphqlizer'
import { createApolloServer } from 'meteor/apollo'
import { makeExecutableSchema } from 'graphql-tools'

// ...

const { typeDefs, resolvers } = generateTypeDefsAndResolvers({
  schemas: [alienSchema],
})

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

createApolloServer({ schema, graphiql: true })

Notice that the generateTypeDefsAndResolvers expects a list of graphqlizer schemas to generate the type definitions and resolvers.

Beyond CRUD

Anytime you need to go beyond the basic CRUD you can use the following composable methods to extend your schema:

  • resolvers(name, Collection[, CustomSimpleSchema]) => {resolverObject} CRUD resolvers
  • typeDefs(name, SimpleSchema) => [String] CRUD type definitions
  • resolver.{create|update|delete|get|list}(Collection[, CustomSimpleSchema]) => Function Specific resolver
  • typeDef.{type|input|create|update|delete|get|list}(name, SimpleSchema) => String Specific type definition
import { resolvers, typeDefs } from 'meteor/easy:graphqlizer'

export default {
  resolvers: {
    ...resolvers('Book', BookCollection),
    Book: {
      relatedMovies (root, args) {
        return /* ... */
      },
    },
  },
  typeDefs: [
    ...typeDefs('Book', BookCollection.simpleSchema()),
    `
    extend type Book {
      relatedMovies: [Movie]   
    }
    `,
  ],
}

In the example above we extend Book with an additional field called relatedMovies. Be aware though that if you want to add a new Query or Mutation you need to use a deep merge function!

If you want to go even more granular you can use the resolver and typeDef functions.

import { resolver, typeDef } from 'meteor/easy:graphqlizer'

export default {
  resolvers: {
    Query: {
      listBook: resolver.list(BookCollection),
      findBookFromFriends (root, args) {
        return /* ... */      
      },
    },
    Mutation: {
      createBook: resolver.create(BookCollection),
    },
  },
  typeDefs: [
    typeDef.type('Book', BookCollection.simpleSchema()),
    typeDef.input('Book', BookCollection.simpleSchema()),
    typeDef.list('Book'),
    typeDef.create('Book'),
    `
    extend type Query {
      findBookFromFriends: [Book]
    }
    `,
  ],
}

This way you can mix and match type definitions and resolvers and if your app grows more complex decouple it from graphqlizer completely, without having to refactor code.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].