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 🙏

© 2025 – Pkg Stats / Ryan Hefner

typed-immutable-graphql

v0.0.1-alpha.2

Published

Typed immutable to graphql conversion

Readme

typed-immutable-graphql

Generate graphql types from typed immutable models. Generate the code in compile time or with npm scripts. Refer example

Install instructions

npm install -D typed-immutable-graphql

Example 1

import { Record } from 'typed-immutable-graphql';

const Ticket = Record({
      id: Number,
      name: String,
    }, 'Ticket');

Ticket.resolve() will yield you the following string

import {
  GraphQLInt,
  GraphQLNonNull,
  GraphQLObjectType,
  GraphQLString
} from 'graphql/type';

const TicketType = new GraphQLObjectType({
  name: 'TicketType',
  fields: {
      id : {
        type: new GraphQLNonNull(GraphQLInt),
      },
      name : {
        type: new GraphQLNonNull(GraphQLString),
      }
  }
}); 

Example 2 (With resolvers)

const Ticket = Record({
      id: Maybe(String),
      message: Number,
    }, 'Ticket');

    const Member = Record({
      id: String,
      tickets: Ticket,
    }, 'Member');

    //resolve map for ticket model
    const ticketResolveMap = {
      'message': function resolve(member){
        return [
          {id: 1, message: `Member: ${member.id}, Ticket: 1`},
          {id: 2, message: `Member: ${member.id}, Ticket: 2`}
        ];
      } 
    };
    //resolveMap for member which will be exposed
    const resolveMap = {
      'tickets': function resolve(member){
        return [
          {id: 1, message: `Member: ${member.id}, Ticket: 1`},
          {id: 2, message: `Member: ${member.id}, Ticket: 2`}
        ];
      } 
    };
    resolveMap[Ticket] = ticketResolveMap;

Member.resolve(resolveMap) will yield you the following string

import {
  GraphQLInt,
  GraphQLNonNull,
  GraphQLObjectType,
  GraphQLString
} from 'graphql/type';

const TicketType = new GraphQLObjectType({
  name: 'TicketType',
  fields: {
      id : {
        type: GraphQLString,
      },
      message : {
        type: new GraphQLNonNull(GraphQLInt),
	 resolve(member) {
        return [{ id: 1, message: 'Member: ' + member.id + ', Ticket: 1' }, { id: 2, message: 'Member: ' + member.id + ', Ticket: 2' }];
      }
      }
  }
});

const MemberType = new GraphQLObjectType({
  name: 'MemberType',
  fields: {
      id : {
        type: new GraphQLNonNull(GraphQLString),
      },
      tickets : {
        type: new GraphQLNonNull(TicketType),
	 resolve(member) {
        return [{ id: 1, message: 'Member: ' + member.id + ', Ticket: 1' }, { id: 2, message: 'Member: ' + member.id + ', Ticket: 2' }];
      }
      }
  }
});

Example 3 (Nested expression)

const Ticket = Record({
      id: Maybe(String),
      type: Maybe(String),
    }, 'Ticket');

    const Member = Record({
      id: Maybe(String),
      name: Maybe(String),
      tickets: Maybe(List(Ticket))
    }, 'Member');

    const Project = Record({
      id: Maybe(Number),
      type: Maybe(String),
      tickets: List(Member),
      members: Maybe(List(Ticket)),
    }, 'Project');

Project.resolve() will yield you the following string

import {
  GraphQLInt,
  GraphQLList,
  GraphQLNonNull,
  GraphQLObjectType,
  GraphQLString
} from 'graphql/type';

const TicketType = new GraphQLObjectType({
  name: 'TicketType',
  fields: {
      id : {
        type: GraphQLString,
      },
      type : {
        type: GraphQLString,
      }
  }
});

const MemberType = new GraphQLObjectType({
  name: 'MemberType',
  fields: {
      id : {
        type: GraphQLString,
      },
      name : {
        type: GraphQLString,
      },
      tickets : {
        type: new GraphQLList(TicketType),
      }
  }
});

const ProjectType = new GraphQLObjectType({
  name: 'ProjectType',
  fields: {
      id : {
        type: GraphQLInt,
      },
      type : {
        type: GraphQLString,
      },
      tickets : {
        type: new GraphQLNonNull(new GraphQLList(MemberType)),
      },
      members : {
        type: new GraphQLList(TicketType),
      }
  }
});

Example 4 (Enum)

 const EnumVal = Typed.Enum({
      SALARY: 'SALARY',
      HOURLY: 'HOURLY',
    },'EnumVal');

    const Employee = Record({
      id: String,
      salaryType: EnumVal,
    }, 'Employee')

Employee.resolve() will yield the following string

import {
  GraphQLEnumType,
  GraphQLNonNull,
  GraphQLObjectType,
  GraphQLString
} from 'graphql/type';

const EnumValType = new GraphQLEnumType({
  name: 'EnumValType',
  values: {
    SALARY: { value: 'SALARY' },
    HOURLY: { value: 'HOURLY' }
  },
});

const EmployeeType = new GraphQLObjectType({
  name: 'EmployeeType',
  fields: {
      id : {
        type: new GraphQLNonNull(GraphQLString),
      },
      salaryType : {
        type: new GraphQLNonNull(EnumValType),
      }
  }
});

You can place the generated code the code at compile time with a hook and use it.

Not sure how useful this project is. Refer test for more examples

License

MIT