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

feat: create squiggle mutation #172

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions server/schema/squiggle/squiggle.datasources.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,22 @@ const find = async (query, limit, offset) => {
}
};

const create = async (squiggleType, content) => {
try {
const _squiggle = await SquiggleModel.create({
squiggleType,
content,
});
return _squiggle;
} catch (error) {
throw APIError(null, error);
}
};
rutajdash marked this conversation as resolved.
Show resolved Hide resolved
const SquiggleDataSources = () => ({
getLatest,
findByID,
find,
create,
});

module.exports = SquiggleDataSources;
17 changes: 17 additions & 0 deletions server/schema/squiggle/squiggle.mutation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { GraphQLObjectType, GraphQLNonNull, GraphQLString } = require('../scalars');
const { createSquiggle } = require('./squiggle.resolver');

const SquiggleType = require('./squiggle.type');

module.exports = new GraphQLObjectType({
name: 'SquiggleMutation',
fields: {
createSquiggle: {
type: SquiggleType,
args: {
content: { type: new GraphQLNonNull(GraphQLString) },
},
resolve: createSquiggle,
},
},
});
9 changes: 9 additions & 0 deletions server/schema/squiggle/squiggle.resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ const { APIError } = require('../../utils/exception');
const DEF_LIMIT = 10;
const DEF_OFFSET = 0;
module.exports = {
createSquiggle: async (_parent, { squiggleType, content }, { API: { Squiggle } }) => {
try {
const _squiggle = await Squiggle.create(squiggleType, content);

rutajdash marked this conversation as resolved.
Show resolved Hide resolved
return _squiggle;
} catch (error) {
throw APIError(null, error);
}
},
getLatestSquiggle: async (_parent, _args, { API: { Squiggle } }, _) => {
try {
const _squiggle = await Squiggle.getLatest();
Expand Down
2 changes: 2 additions & 0 deletions server/schema/squiggle/squiggle.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ const {
// GraphQLJSONObject,
} = require('../scalars');

const SquiggleMutation = require('./squiggle.mutation');
const SquiggleQuery = require('./squiggle.query');
const SquiggleType = require('./squiggle.type');

module.exports = new GraphQLSchema({
types: [SquiggleType],
query: SquiggleQuery,
mutation: SquiggleMutation,
});