Skip to content

Commit

Permalink
fix(mirage): update mirage schema and fix generic scalar type
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Metzener authored and anehx committed May 22, 2019
1 parent 3c2bf1d commit c1cdaa1
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 31 deletions.
2 changes: 1 addition & 1 deletion addon-mirage-support/factories/form.js
Expand Up @@ -5,5 +5,5 @@ export default Factory.extend({
slug: i => `form-${i + 1}`,
description: () => faker.lorem.paragraph(),
isArchived: false,
meta: JSON.stringify({})
meta: () => ({})
});
2 changes: 1 addition & 1 deletion addon-mirage-support/factories/option.js
Expand Up @@ -3,5 +3,5 @@ import { Factory } from "ember-cli-mirage";
export default Factory.extend({
slug: i => `option-${i + 1}`,
label: i => `Option ${i + 1}`,
meta: JSON.stringify({})
meta: () => ({})
});
2 changes: 1 addition & 1 deletion addon-mirage-support/factories/question.js
Expand Up @@ -20,7 +20,7 @@ export default Factory.extend({
isRequired: () => faker.random.boolean().toString(),
isHidden: "false",
isArchived: false,
meta: JSON.stringify({}),
meta: () => ({}),

afterCreate(question, server) {
if (["TEXT", "TEXTAREA"].includes(question.type)) {
Expand Down
14 changes: 7 additions & 7 deletions addon/-private/fragment-types.js
Expand Up @@ -15,10 +15,7 @@ export default {
name: "Document"
},
{
name: "FileAnswer"
},
{
name: "File"
name: "FormAnswer"
},
{
name: "Case"
Expand Down Expand Up @@ -90,7 +87,10 @@ export default {
name: "TableAnswer"
},
{
name: "FormAnswer"
name: "FileAnswer"
},
{
name: "File"
},
{
name: "SimpleTask"
Expand Down Expand Up @@ -168,7 +168,7 @@ export default {
name: "Answer",
possibleTypes: [
{
name: "FileAnswer"
name: "FormAnswer"
},
{
name: "StringAnswer"
Expand All @@ -189,7 +189,7 @@ export default {
name: "TableAnswer"
},
{
name: "FormAnswer"
name: "FileAnswer"
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions addon/mirage-graphql/handler.js
Expand Up @@ -27,8 +27,8 @@ export default function(server) {
schema,
mocks: {
...mocks,
JSONString: () => '{"foo": "bar"}',
GenericScalar: value => value,
JSONString: () => JSON.stringify({}),
GenericScalar: () => ({}),
Node: (_, { id }) => ({ __typename: atob(id).split(":")[0] })
},
preserveResolvers: false
Expand Down
12 changes: 11 additions & 1 deletion addon/mirage-graphql/resolvers/index.js
@@ -1,5 +1,15 @@
import { GraphQLDateTime } from "graphql-iso-date";

export default {
DateTime: GraphQLDateTime
DateTime: GraphQLDateTime,
// generic scalar serializes from a string to an object but deserializes as
// object for some reason ¯\_(ツ)_/¯. But hey, it works!
GenericScalar: {
serialize(str) {
return typeof str === "string" ? JSON.parse(str) : str;
},
deserialize(obj) {
return obj;
}
}
};

0 comments on commit c1cdaa1

Please sign in to comment.