Skip to content

Commit

Permalink
fix: remove input obj in graphql query
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Shih authored and awinberg-aws committed Jul 21, 2023
1 parent 56518d3 commit 690f928
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4440,11 +4440,7 @@ export default function PostUpdateForm(props) {
? (
await API.graphql({
query: getPost,
variables: {
input: {
id: idProp,
},
},
variables: { id: idProp },
})
).data.getPost
: postModelProp;
Expand All @@ -4453,11 +4449,7 @@ export default function PostUpdateForm(props) {
? (
await API.graphql({
query: commentsByPostID,
variables: {
input: {
postID: record.id,
},
},
variables: { postID: record.id },
})
).data.commentsByPostID.items
: [];
Expand Down Expand Up @@ -5172,11 +5164,7 @@ export default function MyPostForm(props) {
? (
await API.graphql({
query: getPost,
variables: {
input: {
id: idProp,
},
},
variables: { id: idProp },
})
).data.getPost
: postModelProp;
Expand Down Expand Up @@ -5934,11 +5922,7 @@ export default function CommentUpdateForm(props) {
? (
await API.graphql({
query: getComment,
variables: {
input: {
id: idProp,
},
},
variables: { id: idProp },
})
).data.getComment
: commentModelProp;
Expand Down Expand Up @@ -6645,11 +6629,7 @@ export default function CommentUpdateForm(props) {
? (
await API.graphql({
query: getComment,
variables: {
input: {
id: idProp,
},
},
variables: { id: idProp },
})
).data.getComment
: commentModelProp;
Expand Down Expand Up @@ -7347,11 +7327,7 @@ export default function ClassUpdateForm(props) {
? (
await API.graphql({
query: getClass,
variables: {
input: {
id: idProp,
},
},
variables: { id: idProp },
})
).data.getClass
: classModelProp;
Expand Down Expand Up @@ -7994,11 +7970,7 @@ export default function UpdateCPKTeacherForm(props) {
? (
await API.graphql({
query: getCPKTeacher,
variables: {
input: {
id: idProp,
},
},
variables: { id: idProp },
})
).data.getCPKTeacher
: cPKTeacherModelProp;
Expand All @@ -8019,11 +7991,7 @@ export default function UpdateCPKTeacherForm(props) {
? (
await API.graphql({
query: cPKProjectsByCPKTeacherID,
variables: {
input: {
cPKTeacherID: record.id,
},
},
variables: { cPKTeacherID: record.id },
})
).data.cPKProjectsByCPKTeacherID.items
: [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1155,11 +1155,7 @@ export default function CollectionOfCustomButtons(
const buttonColorFilterObj = { userID: { eq: \\"[email protected]\\" } };
const buttonColorDataStore = API.graphql({
query: listUserPreferences,
variables: {
input: {
...buttonColorFilterObj,
},
},
variables: { ...buttonColorFilterObj },
}).items[0];
const buttonColor =
buttonColorProp !== undefined ? buttonColorProp : buttonColorDataStore;
Expand All @@ -1168,11 +1164,7 @@ export default function CollectionOfCustomButtons(
};
const buttonEnabledDataStore = API.graphql({
query: listUserPreferences,
variables: {
input: {
...buttonEnabledFilterObj,
},
},
variables: { ...buttonEnabledFilterObj },
}).items[0];
const buttonEnabled =
buttonEnabledProp !== undefined
Expand Down
25 changes: 18 additions & 7 deletions packages/codegen-ui-react/lib/utils/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export const getGraphqlQueryForModel = (action: ActionType, model: string, byFie
}
};

/* istanbul ignore next */
export const isGraphqlQueryAction = (action: ActionType) => {
return [ActionType.GET_BY_RELATIONSHIP, ActionType.GET, ActionType.LIST].includes(action);
};

/**
* Returns a GraphQL call expression and adds to importCollection.
*
Expand Down Expand Up @@ -102,7 +107,7 @@ export const getGraphqlCallExpression = (

importCollection.addMappedImport(ImportValue.API);

if (action === ActionType.LIST || action === ActionType.GET || action === ActionType.GET_BY_RELATIONSHIP) {
if (isGraphqlQueryAction(action)) {
importCollection.addGraphqlQueryImport(query);
} else {
importCollection.addGraphqlMutationImport(query);
Expand All @@ -112,12 +117,18 @@ export const getGraphqlCallExpression = (
graphqlOptions.push(...variables);
} else {
if (variables?.inputs) {
graphqlVariables.push(
factory.createPropertyAssignment(
factory.createIdentifier('input'),
factory.createObjectLiteralExpression(variables.inputs, true),
),
);
if (isGraphqlQueryAction(action)) {
variables.inputs.forEach((variable) => {
graphqlVariables.push(variable);
});
} else {
graphqlVariables.push(
factory.createPropertyAssignment(
factory.createIdentifier('input'),
factory.createObjectLiteralExpression(variables.inputs, true),
),
);
}
}
// filter applies to list
if ((action === ActionType.LIST || action === ActionType.GET_BY_RELATIONSHIP) && variables?.filters) {
Expand Down

0 comments on commit 690f928

Please sign in to comment.