maoosi / prisma-appsync

⚡ Turns your ◭ Prisma Schema into a fully-featured GraphQL API, tailored for AWS AppSync.
https://prisma-appsync.vercel.app
BSD 2-Clause "Simplified" License
226 stars 18 forks source link

Issue: tweaking graphql schema not working #166

Closed ocheezyy-lw closed 1 year ago

ocheezyy-lw commented 1 year ago

Per the documentation I have added the following AST comment to a type in my schema (trying to override a query name)

/// @gql(queries: { list: "workerIndustries" })
model worker_industries {
  id          String   @id @default(dbgenerated("public.uuid_generate_v4()")) @db.Uuid
  worker_id   String   @db.Uuid
  industry_id String   @db.Uuid
  created_at  DateTime @default(now()) @db.Timestamptz(6)
  industry    industry @relation(fields: [industry_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
  worker      worker   @relation(fields: [worker_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
}

After doing so I received the following error in the console on yarn run dev

/Users/user/Documents/prisma-appsync/node_modules/@graphql-tools/schema/cjs/addResolversToSchema.js:73
                            throw new Error(`${typeName}.${fieldName} defined in resolvers, but not in schema`);
                                  ^

Error: Query.listWorkerIndustries defined in resolvers, but not in schema
    at addResolversToSchema (/Users/user/Documents/prisma-appsync/node_modules/@graphql-tools/schema/cjs/addResolversToSchema.js:73:35)
    at makeExecutableSchema (/Users/user/Documents/prisma-appsync/node_modules/@graphql-tools/schema/cjs/makeExecutableSchema.js:80:65)
    at generateResolvers (/Users/user/Documents/prisma-appsync/node_modules/amplify-appsync-simulator/src/schema/index.ts:79:25)
    at AmplifyAppSyncSimulator.init (/Users/user/Documents/prisma-appsync/node_modules/amplify-appsync-simulator/src/index.ts:111:39)
    at Object.start (/Users/user/Documents/prisma-appsync/node_modules/prisma-appsync/dist/server/index.js:22:3611)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Proxy.createServer (/Users/user/Documents/prisma-appsync/node_modules/prisma-appsync/dist/server/index.js:22:4516)

I've tried doing it on other models to see if it's something isolated to this one but it doesn't seem to be the case.

Environment info: OS: MacOS 13.6 (ARM) NodeJS: v18.12.1

maoosi commented 1 year ago

@ocheezyy-lw, thanks for reporting. I can confirm this is an issue that currently affects renaming any of the default CRUD operations.

Probably not the response you’d want to hear, but the ability to rename default CRUD operations will be removed from the next Prisma-AppSync release.

The complexity behind the current GraphQL generator has prevented us from adding new features and resolving known issues. As a result, it's been decided to entirely rebuild the Prisma-AppSync GraphQL generator from the ground. Renaming operations is actually affecting many parts of the library and not only the GraphQL Schema output. So, to keep the scope manageable as well as enhance security, we also decided to deprecate the renaming feature.

However, this rewrite allowed us to introduce new features, such as:

So, to go back to your use case you’ll have two choices after the new release: 1/ use the default listWorkerIndustries OR 2/ disable the list operation using the new @gql(queries: { list: null }) and create a custom resolver named workerIndustries.

The new version will be released within the next 10-15 days.

ocheezyy-lw commented 1 year ago

Thanks so much for getting back to me! I completely understand the change, was just a bit confused when following the docs.

I have another question that I'm not sure if it's worth making a new issue for. On this page in the docs there is no mention of AWS_LAMBDA auth. Is that possible to use?

maoosi commented 1 year ago

That's also part of the new release.

Still in testing and not documented yet - but you can install it via yarn add prisma-appsync@preview to use /// @auth(model: [{ allow: lambda }]).

Make sure to switch back to non-preview after the release.