paljs / prisma-tools

Prisma tools to help you generate CRUD system for GraphQL servers
https://paljs.com
MIT License
683 stars 54 forks source link

updateOneUser error with One-to-Many relationship #179

Closed gtolarc closed 3 years ago

gtolarc commented 3 years ago

The following query error occurs in one-to-many relationship. It seems to be a bug. In the basic example, I tried the same test when adding a group to a user, and an same error occurs.

updateOneUser {where: {id: 1}, data: {group: {connect: {id: {set: 1}}}}}

{"errors":[{"message":"Variable \"$data\" got invalid value { set: 1 } at \"data.group.connect.id\"; Expected type Int. Int cannot represent non-integer value: { set: 1 }","locations":[{"line":1,"column":55}],"extensions":{"code":"INTERNAL_SERVER_ERROR","exception":{"stacktrace":["TypeError: Int cannot represent non-integer value: { set: 1 }","    at GraphQLScalarType.coerceInt [as parseValue] (/Users/mk/dev/workspace/et/pm-test/node_modules/graphql/type/scalars.js:55:11)","    at coerceInputValueImpl (/Users/mk/dev/workspace/et/pm-test/node_modules/graphql/utilities/coerceInputValue.js:127:26)","    at coerceInputValueImpl (/Users/mk/dev/workspace/et/pm-test/node_modules/graphql/utilities/coerceInputValue.js:105:35)","    at coerceInputValueImpl (/Users/mk/dev/workspace/et/pm-test/node_modules/graphql/utilities/coerceInputValue.js:105:35)","    at coerceInputValueImpl (/Users/mk/dev/workspace/et/pm-test/node_modules/graphql/utilities/coerceInputValue.js:105:35)","    at coerceInputValueImpl (/Users/mk/dev/workspace/et/pm-test/node_modules/graphql/utilities/coerceInputValue.js:54:14)","    at coerceInputValue (/Users/mk/dev/workspace/et/pm-test/node_modules/graphql/utilities/coerceInputValue.js:37:10)","    at _loop (/Users/mk/dev/workspace/et/pm-test/node_modules/graphql/execution/values.js:107:69)","    at coerceVariableValues (/Users/mk/dev/workspace/et/pm-test/node_modules/graphql/execution/values.js:119:16)","    at getVariableValues (/Users/mk/dev/workspace/et/pm-test/node_modules/graphql/execution/values.js:48:19)","    at buildExecutionContext (/Users/mk/dev/workspace/et/pm-test/node_modules/graphql/execution/execute.js:184:61)","    at executeImpl (/Users/mk/dev/workspace/et/pm-test/node_modules/graphql/execution/execute.js:89:20)","    at Object.execute (/Users/mk/dev/workspace/et/pm-test/node_modules/graphql/execution/execute.js:64:35)","    at /Users/mk/dev/workspace/et/pm-test/node_modules/apollo-server-core/dist/requestPipeline.js:249:48","    at Generator.next (<anonymous>)","    at /Users/mk/dev/workspace/et/pm-test/node_modules/apollo-server-core/dist/requestPipeline.js:8:71"]}}}]}
gtolarc commented 3 years ago

https://github.com/paljs/prisma-tools/blob/master/packages/admin/src/types.ts#L59

I didn't know there was a useSet option in PrismaTable. There is no problem if useSet is set to false.

gtolarc commented 3 years ago

https://github.com/paljs/prisma-tools/blob/master/packages/admin/src/PrismaTable/Form/useActions.ts#L103 It is correct to use 'set' for basic update, but for relationfield, 'set' should not be used to avoid error. Therefore, it seems that the above part needs to be changed 'useSet=false'.

AhmedElywa commented 3 years ago

Thanks for solving this issue will come in the next release. Also, you are welcome to add pull request with your fixes at anytime