Skip to content

Commit

Permalink
added event schemas, models and queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Markkop committed Sep 3, 2019
1 parent 60bf7c9 commit ca91c9c
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/app/data/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
type Product {
"""
The ID of an object
"""
id: ID!
_id: String
title: String
}

type Event {
id: ID!
_id: String
title: String
date: String
description: String
author: String
}

type Query {
product(id: ID!): Product
products: [Product]
event(id: ID!): Event
events: [Event]
}
12 changes: 12 additions & 0 deletions packages/server/data/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
type Event {
"""The ID of an object"""
id: ID!
_id: String
title: String
date: String
description: String
author: String
}

type Product {
"""The ID of an object"""
id: ID!
Expand All @@ -8,4 +18,6 @@ type Product {
type Query {
product(id: ID!): Product
products: [Product]
event(id: ID!): Event
events: [Event]
}
130 changes: 130 additions & 0 deletions packages/server/data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,49 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "event",
"description": null,
"args": [
{
"name": "id",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "Event",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "events",
"description": null,
"args": [],
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "Event",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down Expand Up @@ -132,6 +175,93 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "Event",
"description": null,
"fields": [
{
"name": "id",
"description": "The ID of an object",
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "_id",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "title",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "date",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "description",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "author",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "__Schema",
Expand Down
18 changes: 18 additions & 0 deletions packages/server/graphql/eventType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const graphql = require("graphql");
const globalIdField = require("graphql-relay").globalIdField;

const { GraphQLObjectType, GraphQLString } = graphql;

const EventType = new GraphQLObjectType({
name: "Event",
fields: () => ({
id: globalIdField("events"),
_id: { type: GraphQLString },
title: { type: GraphQLString },
date: { type: GraphQLString },
description: { type: GraphQLString },
author: { type: GraphQLString }
})
});

module.exports = EventType;
15 changes: 15 additions & 0 deletions packages/server/graphql/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const {
} = require("graphql");
const fromGlobalId = require("graphql-relay").fromGlobalId;
const productGraphQLType = require("./productType");
const eventGraphQLType = require("./eventType");
const Product = require("../models/Product");
const Event = require("../models/Event");

const Query = new GraphQLObjectType({
name: "Query",
Expand All @@ -24,6 +26,19 @@ const Query = new GraphQLObjectType({
resolve() {
return Product.find().lean();
}
},
event: {
type: eventGraphQLType,
args: { id: { type: GraphQLNonNull(GraphQLID) } },
resolve(parent, args) {
return Event.findById(fromGlobalId(args.id).id);
}
},
events: {
type: GraphQLList(eventGraphQLType),
resolve() {
return Event.find();
}
}
}
});
Expand Down
10 changes: 10 additions & 0 deletions packages/server/models/Event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var mongoose = require("mongoose");

const EventSchema = new mongoose.Schema({
title: String,
date: String,
description: String,
author: String
});

module.exports = mongoose.model("Event", EventSchema);

0 comments on commit ca91c9c

Please sign in to comment.