Skip to content

Instantly share code, notes, and snippets.

@chickencoder
Last active February 21, 2019 13:32
Show Gist options
  • Save chickencoder/3a3dacbbbc1c6e20ecd3013dbfbc1da2 to your computer and use it in GitHub Desktop.
Save chickencoder/3a3dacbbbc1c6e20ecd3013dbfbc1da2 to your computer and use it in GitHub Desktop.
Make cute little GraphQL APIs

Cute

Make cute little GraphQL APIs

Simple Hello World Query

import { build, query, returns } from 'cute'

const Hello = query('Hello', returns('String', () => 'Hello World'))

export default build(Hello)

Simple Types

const UserType = type('User', {
  id: 'ID'
  username: 'String',
  password: 'String'
})

function resolveUser(args, { User }) {
  return User.findOne(args)
}

const UserQuery = query('user', { id: 'ID' }, returns('User', resolveUser))

build(UserType, UserQuery)

// This will output the following SDL

// type User {
//  username: String
//  password: String
// }

// type Query {
//  user(id: ID): User
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment