Skip to content

Commit

Permalink
fix: enable support for "multipleValues"
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed May 27, 2020
1 parent 224a497 commit 9c1418b
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 176 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import gql from "graphql-tag";
import { CmsModelFieldToGraphQLPlugin } from "@webiny/api-headless-cms/types";
import { i18nFieldType } from "./../graphqlTypes/i18nFieldType";
import { i18nFieldInput } from "./../graphqlTypes/i18nFieldInput";

const createListFilters = ({ field }) => {
return `
Expand All @@ -25,6 +27,10 @@ const plugin: CmsModelFieldToGraphQLPlugin = {
},
createTypeField({ field }) {
const localeArg = "(locale: String)";
if (field.multipleValues) {
return `${field.fieldId}${localeArg}: [Boolean]`;
}

return `${field.fieldId}${localeArg}: Boolean`;
}
},
Expand All @@ -38,31 +44,23 @@ const plugin: CmsModelFieldToGraphQLPlugin = {
createSchema() {
return {
typeDefs: gql`
input CmsBooleanLocalizedInput {
value: Boolean
locale: ID!
}
input CmsBooleanInput {
values: [CmsBooleanLocalizedInput]
}
type CmsBooleanLocalized {
value: Boolean
locale: ID!
}
type CmsBoolean {
value: Boolean
values: [CmsBooleanLocalized]!
}
${i18nFieldType("CmsBoolean", "Boolean")}
${i18nFieldInput("CmsBoolean", "Boolean")}
`
};
},
createTypeField({ field }) {
if (field.multipleValues) {
return field.fieldId + ": CmsBooleanList";
}

return field.fieldId + ": CmsBoolean";
},
createInputField({ field }) {
if (field.multipleValues) {
return field.fieldId + ": CmsBooleanListInput";
}

return field.fieldId + ": CmsBooleanInput";
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import gql from "graphql-tag";
import { CmsModelFieldToGraphQLPlugin } from "@webiny/api-headless-cms/types";
import { i18nFieldType } from "./../graphqlTypes/i18nFieldType";
import { i18nFieldInput } from "./../graphqlTypes/i18nFieldInput";

const createListFilters = ({ field }) => {
return `
Expand Down Expand Up @@ -43,6 +45,9 @@ const plugin: CmsModelFieldToGraphQLPlugin = {
},
createTypeField({ field }) {
const localeArg = "(locale: String)";
if (field.multipleValues) {
return `${field.fieldId}${localeArg}: [String]`;
}

return `${field.fieldId}${localeArg}: String`;
}
Expand All @@ -57,109 +62,70 @@ const plugin: CmsModelFieldToGraphQLPlugin = {
createSchema() {
return {
typeDefs: gql`
# dateTimeWithTimezone types
input CmsDateTimeWithTzLocalizedInput {
value: String
locale: ID!
}
input CmsDateTimeWithTzInput {
values: [CmsDateTimeWithTzLocalizedInput]
}
type CmsDateTimeWithTzLocalized {
value: String
locale: ID!
}
type CmsDateTimeWithTz {
value: String
values: [CmsDateTimeWithTzLocalized]!
}
# dateTimeWithoutTimezone types
input CmsDateTimeLocalizedInput {
value: String
locale: ID!
}
input CmsDateTimeInput {
values: [CmsDateTimeLocalizedInput]
}
type CmsDateTimeLocalized {
value: String
locale: ID!
}
type CmsDateTime {
value: String
values: [CmsDateTimeLocalized]!
}
# date types
input CmsDateLocalizedInput {
value: String
locale: ID!
}
input CmsDateInput {
values: [CmsDateLocalizedInput]
}
type CmsDateLocalized {
value: String
locale: ID!
}
type CmsDate {
value: String
values: [CmsDateLocalized]!
}
# time types
input CmsTimeLocalizedInput {
value: String
locale: ID!
}
input CmsTimeInput {
values: [CmsTimeLocalizedInput]
}
type CmsTimeLocalized {
value: String
locale: ID!
}
type CmsTime {
value: String
values: [CmsTimeLocalized]!
}
${i18nFieldType("CmsDateTimeWithTz", "String")}
${i18nFieldInput("CmsDateTimeWithTz", "String")}
${i18nFieldType("CmsDateTime", "String")}
${i18nFieldInput("CmsDateTime", "String")}
${i18nFieldType("CmsDate", "String")}
${i18nFieldInput("CmsDate", "String")}
${i18nFieldType("CmsTime", "String")}
${i18nFieldInput("CmsTime", "String")}
`
};
},
createTypeField({ field }) {
switch (field.settings.type) {
case "dateTimeWithTimezone":
if (field.multipleValues) {
return field.fieldId + ": CmsDateTimeWithTzList";
}

return field.fieldId + ": CmsDateTimeWithTz";
case "dateTimeWithoutTimezone":
if (field.multipleValues) {
return field.fieldId + ": CmsDateTimeList";
}

return field.fieldId + ": CmsDateTime";
case "date":
if (field.multipleValues) {
return field.fieldId + ": CmsDateList";
}

return field.fieldId + ": CmsDate";
case "time":
if (field.multipleValues) {
return field.fieldId + ": CmsTimeList";
}

return field.fieldId + ": CmsTime";
}
},
createInputField({ field }) {
switch (field.settings.type) {
case "dateTimeWithTimezone":
if (field.multipleValues) {
return field.fieldId + ": CmsDateTimeWithTzListInput";
}

return field.fieldId + ": CmsDateTimeWithTzInput";
case "dateTimeWithoutTimezone":
if (field.multipleValues) {
return field.fieldId + ": CmsDateTimeListInput";
}

return field.fieldId + ": CmsDateTimeInput";
case "date":
if (field.multipleValues) {
return field.fieldId + ": CmsDateListInput";
}

return field.fieldId + ": CmsDateInput";
case "time":
if (field.multipleValues) {
return field.fieldId + ": CmsTimeListInput";
}

return field.fieldId + ": CmsTimeInput";
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import gql from "graphql-tag";
import { CmsModelFieldToGraphQLPlugin } from "@webiny/api-headless-cms/types";
import { i18nFieldType } from "./../graphqlTypes/i18nFieldType";
import { i18nFieldInput } from "./../graphqlTypes/i18nFieldInput";

const createListFilters = ({ field }) => {
return `
Expand Down Expand Up @@ -31,6 +33,10 @@ const plugin: CmsModelFieldToGraphQLPlugin = {
read: {
createTypeField({ field }) {
const localeArg = "(locale: String)";
if (field.multipleValues) {
return `${field.fieldId}${localeArg}: [String]`;
}

return `${field.fieldId}${localeArg}: String`;
},
createGetFilters({ field }) {
Expand All @@ -53,24 +59,8 @@ const plugin: CmsModelFieldToGraphQLPlugin = {
createSchema() {
return {
typeDefs: gql`
input CmsLongTextLocalizedInput {
value: String
locale: ID!
}
input CmsLongTextInput {
values: [CmsLongTextLocalizedInput]
}
type CmsLongTextLocalized {
value: String
locale: ID!
}
type CmsLongText {
value(locale: String): String
values: [CmsLongTextLocalized]!
}
${i18nFieldType("CmsLongText", "String")}
${i18nFieldInput("CmsLongText", "String")}
`,
resolvers: {
CmsLongText: {
Expand All @@ -82,9 +72,17 @@ const plugin: CmsModelFieldToGraphQLPlugin = {
};
},
createTypeField({ field }) {
if (field.multipleValues) {
return field.fieldId + ": CmsLongTextList";
}

return field.fieldId + ": CmsLongText";
},
createInputField({ field }) {
if (field.multipleValues) {
return field.fieldId + ": CmsLongTextListInput";
}

return field.fieldId + ": CmsLongTextInput";
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import gql from "graphql-tag";
import { CmsModelFieldToGraphQLPlugin } from "@webiny/api-headless-cms/types";
import { i18nFieldType } from "./../graphqlTypes/i18nFieldType";
import { i18nFieldInput } from "./../graphqlTypes/i18nFieldInput";

const createListFilters = ({ field }) => {
return `
Expand Down Expand Up @@ -43,6 +45,10 @@ const plugin: CmsModelFieldToGraphQLPlugin = {
},
createTypeField({ field }) {
const localeArg = "(locale: String)";
if (field.multipleValues) {
return `${field.fieldId}${localeArg}: [Number]`;
}

return `${field.fieldId}${localeArg}: Number`;
}
},
Expand All @@ -56,31 +62,23 @@ const plugin: CmsModelFieldToGraphQLPlugin = {
createSchema() {
return {
typeDefs: gql`
input CmsNumberLocalizedInput {
value: Number
locale: ID!
}
input CmsNumberInput {
values: [CmsNumberLocalizedInput]
}
type CmsNumberLocalized {
value: Number
locale: ID!
}
type CmsNumber {
value: Number
values: [CmsNumberLocalized]!
}
${i18nFieldType("CmsNumber", "Number")}
${i18nFieldInput("CmsNumber", "Number")}
`
};
},
createTypeField({ field }) {
if (field.multipleValues) {
return field.fieldId + ": CmsNumberList";
}

return field.fieldId + ": CmsNumber";
},
createInputField({ field }) {
if (field.multipleValues) {
return field.fieldId + ": CmsNumberListInput";
}

return field.fieldId + ": CmsNumberInput";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const plugin: CmsModelFieldToGraphQLPlugin = {
read: {
createTypeField({ field }) {
const localeArg = "(locale: String)";
if (field.multipleValues) {
return `${field.fieldId}${localeArg}: [JSON]`;
}

return `${field.fieldId}${localeArg}: JSON`;
},
createGetFilters({ field }) {
Expand All @@ -26,8 +30,14 @@ const plugin: CmsModelFieldToGraphQLPlugin = {
},
createTypeField({ field }) {
return field.fieldId + ": CmsJSON";
if (field.multipleValues) {
return field.fieldId + ": CmsJSONList";
}
},
createInputField({ field }) {
if (field.multipleValues) {
return field.fieldId + ": CmsJSONListInput";
}
return field.fieldId + ": CmsJSONInput";
}
}
Expand Down
Loading

0 comments on commit 9c1418b

Please sign in to comment.