Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Graphql Queries for Squiggle #91

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/schema/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ const { stitchSchemas } = require('graphql-tools');
const UserSchema = require('./user/user.schema');
const ArticleSchema = require('./article/article.schema');
const IssueSchema = require('./issue/issue.schema');
const SquiggleSchema = require('./squiggle/squiggle.schema');
const CategoryMapType = require('./categoryMap/categoryMap.type');
const TagType = require('./tag/tag.type');
const MediaType = require('./media/media.type');

module.exports = stitchSchemas({
subschemas: [UserSchema, ArticleSchema, IssueSchema],
subschemas: [UserSchema, ArticleSchema, IssueSchema, SquiggleSchema],
types: [CategoryMapType, TagType, MediaType],
mergeTypes: true,
});
54 changes: 54 additions & 0 deletions server/schema/squiggle/squiggle.query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* @module app.schema.SquiggleQuery
* @description Squiggle Query
*
* @requires module:app.schema.scalars
*
* @version v1
* @since 0.1.0
*/

const {
GraphQLObjectType,
//GraphQLString,
// GraphQLSchema,
GraphQLID,
GraphQLList,
// GraphQLBoolean,
GraphQLInt,
GraphQLNonNull,
// GraphQLDate,
// GraphQLTime,
// GraphQLDateTime,
// GraphQLJSON,
// GraphQLJSONObject,
} = require('../scalars');

const SquiggleType = require('./squiggle.type');
const { getSquiggleByID, listSquiggles } = require('./squiggle.resolver');

module.exports = new GraphQLObjectType({
name: 'SquiggleQuery',
fields: {
getSquiggleByID: {
description: 'Retrieves a single Squiggle',
type: SquiggleType,
args: {
id: {
type: new GraphQLNonNull(GraphQLID),
description: "The squiggle's mongo ID",
},
},
resolve: getSquiggleByID,
},
listSquiggles: {
description: 'Retrieves a list of all the Squiggles',
type: new GraphQLNonNull(new GraphQLList(SquiggleType)),
args: {
offset: { type: GraphQLInt },
limit: { type: GraphQLInt },
},
resolve: listSquiggles,
},
},
});
47 changes: 47 additions & 0 deletions server/schema/squiggle/squiggle.resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @module app.schema.SquiggleResolver
* @description Squiggle Resolver
*
* @requires module:app.schema.SquiggleType
* @requires module:app.schema.SquiggleModel
* @requires module:app.authorization
* @version v1
* @since 0.1.0
*/

const { APIError } = require('../../helpers/errorHandler');
//const { HasPermmission } = require('../../helpers/authorization');

const SquiggleModel = require('./squiggle.model');

const DEF_LIMIT = 10;
const DEF_OFFSET = 0;
module.exports = {
getSquiggleByID: async (_parent, { id }, context, _info, _SquiggleModel = SquiggleModel) => {
try {
const _squiggle = await _SquiggleModel.findById(id);

if (!_squiggle) {
return APIError('NOT_FOUND');
}
return _squiggle;
} catch (e) {
return APIError(null, e);
}
},
listSquiggles: async (
_parent,
{ limit = DEF_LIMIT, offset = DEF_OFFSET },
context,
_info,
_IssueModel = IssueModel
) => {
try {
const _squiggles = await _SquiggleModel.find().skip(offset).limit(limit);

return _squiggles;
} catch (e) {
return APIError(null, e);
}
},
};
32 changes: 32 additions & 0 deletions server/schema/squiggle/squiggle.schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @module app.schema.Squiggle
* @description Squiggle Schema
*
* @requires module:app.schema.scalars
* @requires module:app.schema.SquiggleQuery
*
* @version v1
* @since 0.1.0
*/

const {
// GraphQLObjectType,
// GraphQLString,
GraphQLSchema,
// GraphQLID,
// GraphQLList,
// GraphQLBoolean,
// GraphQLInt,
// GraphQLNonNull,
// GraphQLDate,
// GraphQLTime,
// GraphQLDateTime,
// GraphQLJSON,
// GraphQLJSONObject,
} = require('../scalars');

const SquiggleQuery = require('./squiggle.query');

module.exports = new GraphQLSchema({
query: SquiggleQuery,
});
42 changes: 42 additions & 0 deletions server/schema/squiggle/squiggle.type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @module app.schema.SquiggleType
* @description SquiggleType
*
* @requires module:app.schema.scalars
*
* @version v1
* @since 0.1.0
*/

const {
GraphQLObjectType,
// GraphQLString,
// GraphQLSchema,
GraphQLID,
GraphQLList,
// GraphQLBoolean,
GraphQLInt,
// GraphQLNonNull,
// GraphQLDate,
// GraphQLTime,
GraphQLDateTime,
// GraphQLJSON,
// GraphQLJSONObject,
} = require('../scalars');

const ContentType = require('../common/content.type');

const SquiggleType = new GraphQLObjectType({
name: 'Squiggle',
fields: () => ({
id: { type: GraphQLID },
content: { type: GraphQLList(ContentType) },
createdAt: { type: GraphQLDateTime },
createdBy: { type: GraphQLID },
updatedAt: { type: GraphQLDateTime },
updatedBy: { type: GraphQLID },
schemaVersion: { type: GraphQLInt },
}),
});

module.exports = SquiggleType;