Skip to content

Instantly share code, notes, and snippets.

@taion
Last active June 14, 2016 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taion/eb46f7b241ea9a4deb4373206e547f48 to your computer and use it in GitHub Desktop.
Save taion/eb46f7b241ea9a4deb4373206e547f48 to your computer and use it in GitHub Desktop.
class Post {
static Resource = HttpResource;
static resourceConfig = { endpoint: '/posts' };
@field({ required: true }))
title = 'untitled';
@field()
text = '';
@field({ type: GraphQLInt })
number;
@relationship(() => Author, { authorId: GraphQLString }, { required: True })
author;
// Or maybe:
@field({ required: True }))
author = relationship(() => Author, { authorId: GraphQLString });
@method({ input: GraphQLInt }, GraphQLInt)
square({ input }) {
return input * input;
}
// Not included on the GraphQL type.
propValue = 4;
static extraFields = () => ({
extraField: {
type: GraphQLInt,
resolve: () => 3,
},
});
static mutations = [
CreateMutation,
UpdatePartialMutation,
DeleteMutation,
];
}
// So then when needed you could do:
Author.getResource(context)
Author.Type
Author.ConnectionType
// For a Relay server, you could do:
class Author extends NodeModel { /* ... */ }
// Imagine orm.Post is a Mongoose model or something equivalent.
class Post extends OrmModel(orm.Post) {
static fields = {
number: GraphQLInt,
propValue: null, // Or have a separate excludeFields?
// The rest get included by default.
}
// Maybe?
static methods = {
square: [{ input: GraphQLInt }, GraphQLInt],
}
static extraFields = () => ({
extraField: {
type: GraphQLInt,
resolve: () => 3,
},
});
static mutations = [
CreateMutation,
UpdatePartialMutation,
DeleteMutation,
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment