npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

meteor-schema-graphql-bridge-verso

v1.0.6

Published

Simple Schema - GraphQL Schema Bridge

Downloads

6

Readme

Simple Schema - GraphQL Schema Bridge

Change only your Meteor Simple Schema: GraphQL schema & resolvers are updated automatically.

Define your Simple Schemas for your collection and let schema-graphql-bridge do the tedious work of defining the schema's basic fields and resolvers, for you.

How to use

meteor add kuip:schema-graphql-bridge

  • demo: https://www.youtube.com/watch?v=5Z7ZSUIdamg (be carefull, the API has changed!)

  • take a look at: https://github.com/loredanacirstea/meteor-apollo-react-boilerplate/tree/master/imports/api

  let schema = SchemaBridge.schema(SimpleSchema, name, [options]);
  let resolvers = SchemaBridge.resolvers(SimpleSchema, name, [options]);

Options:

  • wrap: Boolean, default true

    • if set to true, SchemaBridge.schema will return a String with the GraphQL definitions for the SimpleSchema
    • set to false if you want to further edit the GraphQL schema (see examples)
    • if set to false, SchemaBridge.schema will return { objects, fields }
      • objects = GraphQL type definitions for the SimpleSchema objects
      • fields = definitions for the first level SimpleSchema fields
  • fields: [String]

    • Write schema definitions/resolvers only for these fields(*)
  • except:[String]

    • Write schema definitions/resolvers for all fields except these(*)
  • custom: Object

    • Custom values for the schema fields
  custom: {
     user: 'User',
  },

(*) fields = SimpleSchema._firstLevelSchemaKeyss

Simple Schema example:

  const subList = new SimpleSchema({
    field3: {
      type: Object
    },
    'field3.attr': {
      type: Object,
    },
    'field3.attr.something': {
      type: String
    }
  });

  Lists.schema = new SimpleSchema({
    _id: {
      type: String
    },
    title: { 
      type: String 
    },
    description: { 
      type: String 
    },
    sublist: {
      type: subList,
      optional: true
    },
  });

Define your GraphQL schema

  // .../lists-schema.js
  import SchemaBridge from 'meteor/kuip:schema-graphql-bridge';
  import Lists from './lists';

  // Entire schema for the List entity:
  const listSchema = SchemaBridge.schema(Lists.schema, 'List');
  export default listSchema;

  // If you want to modify it afterwards:
  let listDefs = SchemaBridge.schema(Lists.schema, 'List', {wrap: false});

  const listSchema = `
    ${listDefs.objects}
    type List {
      ${listDefs.fields}
      tasks: [Task]
   }`;
  export default taskSchema;

Define your GraphQL resolvers

  import SchemaBridge from 'meteor/kuip:schema-graphql-bridge';
  import Lists from './lists';
  import Tasks from '../tasks/tasks';

  let listResolvers = SchemaBridge.resolvers(Lists.schema, 'List');

  listResolvers.List.tasks = (root, args, context) => {
    return Tasks.find({list: root._id}).fetch();
  };

  export default listResolvers;

This package and the above code replaces:

  type ListSublistField3Attr {
    something: ListSublistField3AttrSomething
  }
  type ListSublistField3 {
    attr: ListSublistField3Attr
  }
  type ListSublist {
    field3: ListSublistField3
  }
  type List {
    _id: String
    title: String 
    description: String 
    sublist: ListSublist
  }
  const resolvers = {
    List: {
      title: ({ title }) => title,
      description: ({ description }) => description,
      sublist: ({ sublist }) => sublist,
    },
    ListSublist: {
      field3: ({ field3 }) => field3
    },
    ListSublistField3: {}
  }

Simple Schema types supported

Should work with all types.

  • Date is transformed into String
  • Objects are transformed into GraphQL object types, with a camel cased name, based on it's SimpleSchema path.