Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

typiql

touchbistro25MITdeprecated0.3.0

this package has been deprecated

Helper for referencing graphql-js types

graphql

readme

typiql

CircleCI

typiql is a micro-helper for graphql-js that lets you refer to your GraphQL types more succinctly.

typiql is not for building entire schemas. It's only for use with the type property of your GraphQL fields. You still define GraphQLObjectType and GraphQLInputObjectTypes with normal graphql-js syntax, but when declaring your fields' types, use tql shorthand to refer to scalars, custom objects, and wrapping types.

Examples

Built in scalars

tql`String`     // => GraphQLString
tql`Int`        // => GraphQLInt

Non-null scalar

tql`ID!`        // => new GraphQLNonNull(GraphQLID)

Non-null list of non-null floats

tql`[Float!]!`  // => new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLFloat)))

List of custom object types

tql`[${BeerType}]` // => new GraphQLList(BeerType)

Detailed example

npm install --save typiql
import tql from 'typiql'
import {
  GraphQLObjectType
} from 'graphql'

const CommentType = new GraphQLObjectType({
  name: 'Comment',
  fields: () => {
    id: { type: tql`ID!` },          // => new GraphQLNonNull(GraphQLID)
    text: { type: tql`String!` },    // => new GraphQLNonNull(GraphQLString)
    post: {
      type: tql`${PostType}!`,       // => new GraphQLNonNull(PostType)
      resolve: () => { /* ... */ }
    }
  }
})

const PostType = new GraphQLObjectType({
  name: 'Post',
  fields: () => {
    id: { type: tql`ID!` },           // => new GraphQLNonNull(GraphQLID)
    title: { type: tql`String!` },    // => new GraphQLNonNull(GraphQLString)
    comments: {
      type: tql`[${CommentType}!]`,   // => new GraphQLList(new GraphQLNonNull(CommentType))
      resolve: () => { /* ... */ }
    }
  }
})

Notes

  • typiql is not intended for constructing your entire schema using the GraphQL schema IDL. For this, consider one of the other tools listed here.

  • typiql does not require/implement a custom type registry. Import your actual types, and interpolate them.

  • typiql gives you a slightly better experience than stock graphql-js, while still allowing you to build your schema programatically, as well as keep your resolvers next to your fields. (typiql does not require your types and resolvers in separate parallel structures, like some other schema building tools).

changelog

0.1.0

  • Initial version.

0.1.1

  • Loosen peerDependency on graphql-js to ^0.6.2.

0.1.2

  • Loosen peerDependency on graphql-js to >=0.6.2.

0.2.0

  • Add flowtype annotations.
  • Upgrade dev dependencies.

0.2.1

  • Use flow-copy-source to build a .js.flow file in the build directory, so npm users can use the flowtypes.

0.2.2

  • Use babel-plugin-add-module-exports for compatibility with CommonJS require syntax.
  • This version was released by mistake without building.

0.2.3

  • Use babel-plugin-add-module-exports for compatibility with CommonJS require syntax (thanks to @VorontsovMaxim for PR)

0.3.0

  • [BREAKING] Fix bug where [Foo]! and [Foo!] were reversed. (thanks to @VorontsovMaxim for PR)