Skip to content

Commit

Permalink
fixes: Weakky#36
Browse files Browse the repository at this point in the history
  • Loading branch information
macrozone committed Mar 29, 2019
1 parent 16a6e42 commit 7df730d
Showing 1 changed file with 37 additions and 49 deletions.
86 changes: 37 additions & 49 deletions src/buildVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,17 +256,26 @@ const buildUpdateVariables = (introspectionResults: IntrospectionResult) => (
) => {
return Object.keys(params.data).reduce(
(acc, key) => {
if (Array.isArray(params.data[key])) {
const inputType = findInputFieldForType(
introspectionResults,
`${resource.type.name}UpdateInput`,
key
);
// Put id field in a where object
if (key === 'id' && params.data[key]) {
return {
...acc,
where: {
id: params.data[key]
}
};
}
const inputType = findInputFieldForType(
introspectionResults,
`${resource.type.name}UpdateInput`,
key
);

if (!inputType) {
return acc;
}
if (!inputType) {
return acc;
}

if (Array.isArray(params.data[key])) {
//TODO: Make connect, disconnect and update overridable
//TODO: Make updates working
const {
Expand All @@ -291,16 +300,6 @@ const buildUpdateVariables = (introspectionResults: IntrospectionResult) => (
}

if (isObject(params.data[key])) {
const inputType = findInputFieldForType(
introspectionResults,
`${resource.type.name}UpdateInput`,
key
);

if (!inputType) {
return acc;
}

if (inputType.kind !== 'SCALAR') {
const typeName = `${resource.type.name}UpdateInput`;

Expand All @@ -320,16 +319,6 @@ const buildUpdateVariables = (introspectionResults: IntrospectionResult) => (
}
}

// Put id field in a where object
if (key === 'id' && params.data[key]) {
return {
...acc,
where: {
id: params.data[key]
}
};
}

const type = introspectionResults.types.find(
t => t.name === resource.type.name
) as IntrospectionObjectType;
Expand Down Expand Up @@ -362,17 +351,26 @@ const buildCreateVariables = (introspectionResults: IntrospectionResult) => (
) =>
Object.keys(params.data).reduce(
(acc, key) => {
if (Array.isArray(params.data[key])) {
if (
!inputFieldExistsForType(
introspectionResults,
`${resource.type.name}CreateInput`,
key
)
) {
return acc;
}
// Put id field in a where object
if (key === 'id' && params.data[key]) {
return {
...acc,
where: {
id: params.data[key]
}
};
}

const inputType = findInputFieldForType(
introspectionResults,
`${resource.type.name}UpdateInput`,
key
);

if (!inputType) {
return acc;
}
if (Array.isArray(params.data[key])) {
return {
...acc,
data: {
Expand Down Expand Up @@ -415,16 +413,6 @@ const buildCreateVariables = (introspectionResults: IntrospectionResult) => (
}
}

// Put id field in a where object
if (key === 'id' && params.data[key]) {
return {
...acc,
where: {
id: params.data[key]
}
};
}

const type = introspectionResults.types.find(
t => t.name === resource.type.name
) as IntrospectionObjectType;
Expand Down

0 comments on commit 7df730d

Please sign in to comment.