Skip to content

Instantly share code, notes, and snippets.

@taion taion/Post.js
Last active Jun 14, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.