Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect in update mutation #46

Closed
gtolarc opened this issue Dec 1, 2020 · 19 comments
Closed

connect in update mutation #46

gtolarc opened this issue Dec 1, 2020 · 19 comments
Labels

Comments

@gtolarc
Copy link

gtolarc commented Dec 1, 2020

<ReferenceInput label="Shop" source="shopId" reference="Shop">
    <SelectInput optionText="name" />
</ReferenceInput>

ReferenceInput is not automatically converted to 'connect' format. If source="shop.connect.id" is used, it works functionally, but the existing shopId is not recognized in the edit screen.

Is there a solution to this?

@gtolarc
Copy link
Author

gtolarc commented Dec 1, 2020

It seems that nexus-plugin-prisma removes relation id(in this case, shopId) from update mutation when building crud.

If this is intended, I think ReferenceInput should be automatically changed to use 'create/connect'. Or, it would be nice if there was an option to use the shopId of source for query and shop.connect.id for mutation. Like this,

<ReferenceInput label="Shop" source="shopId" sourceOut="shop.connect.id" reference="Shop">
    <SelectInput optionText="name" />
</ReferenceInput>

@gtolarc
Copy link
Author

gtolarc commented Dec 1, 2020

marmelab/react-admin#5608 (comment) I got this answer, can you guys fix it?

@macrozone
Copy link
Member

macrozone commented Dec 1, 2020

@gtolarc did you try

<ReferenceInput label="Shop" source="shop" reference="Shop">
    <SelectInput optionText="name" />
</ReferenceInput>

?

that should convert it to connect. We use that in a lot of places

@gtolarc
Copy link
Author

gtolarc commented Dec 1, 2020

yes, if source="shop" is used, it is requested as follows.
스크린샷 2020-12-01 오후 6 28 51

@gtolarc
Copy link
Author

gtolarc commented Dec 1, 2020

This is my schema.prisma

model Shop {
  @@map(name: "shop")

  id          Int         @id @default(autoincrement())
  name        String?
  itemInfos   ItemInfo[]
}

model ItemInfo {
  @@map(name: "itemInfo")

  id          Int         @id @default(autoincrement())
  name        String?
  shopId      Int?
  shop        Shop?       @relation(fields: [shopId], references: [id])
}

and types

const Shop = objectType({
  name: 'Shop',
  definition(t) {
    t.model.id();
    t.model.name();
    t.model.itemInfos();
  },
});
const ItemInfo = objectType({
  name: 'ItemInfo',
  definition(t) {
    t.model.id();
    t.model.name();
    t.model.shopId();
    t.model.shop();
  },
});

@gtolarc
Copy link
Author

gtolarc commented Dec 1, 2020

lib vers.

{
  "dependencies": {
    "@nexus/schema": "^0.19.2",
    "@prisma/client": "^2.12.1",
    "@ra-data-prisma/backend": "^4.0.0",
    "graphql": "^15.4.0",
    "nexus-plugin-prisma": "^0.25.0",
  },
  "devDependencies": {
    "@prisma/cli": "^2.12.1",
  }
}

@macrozone
Copy link
Member

@gtolarc did you define both as Resources as described in the readme by calling addCrudResolvers on both Shop and ItemInfo?

@gtolarc
Copy link
Author

gtolarc commented Dec 1, 2020

Yes, this is my related code. There seems to be a part where I made a mistake, but I don't know where it is. There seems to be no problem with the points you gave me.

const schema = makeSchema({
  types: [
    Shop,
    addCrudResolvers('Shop'),
    ItemInfo,
    addCrudResolvers('ItemInfo'),
  ],
  plugins: [
    nexusPrisma({
      experimentalCRUD: true,
      paginationStrategy: 'prisma',
      outputs: {
        typegen: path.resolve(__dirname, 'generated/nexus-prisma.d.ts'),
      },
    }),
  ],
  outputs: {
    typegen: path.resolve(__dirname, 'generated/nexus.d.ts'),
    schema: path.resolve(__dirname, 'generated/schema.gql'),
  },
});

@macrozone
Copy link
Member

@gtolarc no worries, maybe i am also wrong. I'll try to reproduce it in the project

@macrozone
Copy link
Member

lib vers.

{
  "dependencies": {
    "@nexus/schema": "^0.19.2",
    "@prisma/client": "^2.12.1",
    "@ra-data-prisma/backend": "^4.0.0",
    "graphql": "^15.4.0",
    "nexus-plugin-prisma": "^0.25.0",
  },
  "devDependencies": {
    "@prisma/cli": "^2.12.1",
  }
}

you do not seem to use the dataprovider, you need to use @ra-data-prisma/dataprovider as well

@gtolarc
Copy link
Author

gtolarc commented Dec 1, 2020

Sorry for the confusion. The version mentioned above is what I used in the backend, and I used @ra-data-prisma/dataprovider in the front as well.

@macrozone
Copy link
Member

macrozone commented Dec 1, 2020

@gtolarc be aware that the latest supported version of nexus-plugin-prisma is 0.18.2. support for 0.25. is planned, but i had not had the chance to do it yet.

a short test shows that its not compatible yet

@macrozone
Copy link
Member

@gtolarc indeed, the test ist failing with 0.25: #47

@macrozone
Copy link
Member

@gtolarc i fixed the problem with nexus-plugin-prisma 0.25. in #47

it should be released as version 5 as its a breaking change.

macrozone added a commit that referenced this issue Dec 1, 2020
BREAKING CHANGE: nexus-plugin-prisma < 0.25 is no longer supported

BREAKING CHANGE: prisma < 2.12.x is no longer supported

BREAKING CHANGE: nexus framework is no longer supported as this has been discontinued

fixes #46

fixes #44

fixes #42
@macrozone
Copy link
Member

🎉 This issue has been resolved in version 5.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@macrozone
Copy link
Member

🎉 This issue has been resolved in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gtolarc
Copy link
Author

gtolarc commented Dec 2, 2020

Thank you! Awesome! @macrozone

@macrozone
Copy link
Member

@gtolarc can you check if it works?

@gtolarc
Copy link
Author

gtolarc commented Dec 2, 2020

Sure, it's working properly. @macrozone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants