Scaffold GraphQL Meteor Apps with Maka-CLI, Part 1

$ maka create graphql-service --graphql=apollo
meat and potatoes
$ maka g:api Trucks
  • fixtures.jsx: Only on app startup, these commands will run.
  • publications.jsx: What this API will publish to the world through Meteor’s pub/sub paradigm.
  • rpc-methods.jsx: RPC methods that may be called by the client.
  • trucks-collection.jsx: The Mongo definition of Trucks.

Show me Show me Show me!

Now that you have an idea of what’s going on behind the scenes let’s see that GraphQL in action by using the included “GraphQL” playground. We’re just going to run the only defined query we have, which is “trucks.” http://localhost:3000/graphql

Trucks.find({ }).fetch();
$ maka mongo
db.Trucks.insert({ model: 'Tacoma', make: 'Toyota' });
curl 'http://localhost:3000/graphql' -H 'Content-Type: application/json' --data-binary '{"query":"query { trucks { model  make }}"}'
meat and potatoes with butter
import { resolvers as trucksResolvers } from '/imports/api/trucks/graphql/resolvers.jsx'import { typeDefs as trucksTypeDefs } from '/imports/api/trucks/graphql/typeDefs.jsx'
const typeList = [];
const resolverList = [];

Take away:

Other than the apparent scaffolding of a new Meteor app, implementing a GraphQL service, and setting up some Trucks API, we’ve set up something far more impressive: organized our GraphQL endpoint into a clearly defined resource. As you add more resources, you’ll find that keeping the typeDefs and resolvers small and separate from each other will make your life a lot easier.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store