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
Add an option (or a way) to force Prisma return all scalar entity properties #194
Comments
Hey @terion-name 👋 This is a great question. I would suggest you check out
The In the export const File = {
fragment: `fragment FilePath on File { path }`,
resolve: async ({ path }, args, ctx, info) => {
return generateUrl(path)
}
} This should resolve your use case, so I'm closing this issue 🙂Let me know if there's anything else you want to learn about this! |
@marktani I can't make it work :( Not with files, with another model: type Link {
id: ID! @unique
link: String!
order: Int!
status: LINK_STATUS @default(value: "INACTIVE")
translations: [LinkTranslation!]!
} resolver:
resolver: function (p, args, ctx, info) {
console.log(p);
return p.link;
} Query:
Console output:
Server — It does not contain order :( This also doesn't work:
|
I’m also struggling with this and graphql-yoga, did you ever get it to work? |
@gazzer82 nope ( |
Hey @terion-name 👋, Can you double check that you extracted fragment replacements from resolvers and applied them to // resolvers.ts
import { extractFragmentReplacements } from 'prisma-binding'
// Query
import { Query } from './Query'
...
export const resolvers = {
Query,
...
UserFollowedBy,
AuthPayload,
}
export const fragmentReplacements = extractFragmentReplacements(resolvers)
// index.ts
import { resolvers, fragmentReplacements } from './resolvers'
const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: req => ({
...req,
db: new Prisma({
fragmentReplacements, // <--
endpoint: process.env.PRISMA_ENDPOINT,
secret: process.env.PRISMA_SECRET,
}),
}),
}) I hope this helps 🙂 |
@maticzav and how does resolver (e.g. |
# schema.graphql
type Image {
id: ID!
url: String!
}
# datamodel.graphql
type Image {
id: ID!
createdAt: DateTime!
updatedAt: DateTime!
owner: User! @relation(name: "UserImage")
} import { Context } from '../utils'
export const Image = {
url: {
fragment: `fragment ImageID on Image { id }`,
resolve: async ({ id }, args, ctx: Context, info) => {
return `http://cdn.myservice.com/${id}`
},
}
} |
Hey @marktani. The sample project does not have a |
IMHO it is a must-have feature and one of those, that make it very hard to make anything more than a primitive CRUD on top of Prisma.
We use prisma bindings mostly to proxy client requests to Prisma, passing down
info
object. In response it will return the data, that is requested and only it. But this approach fails with custom fields.Example situation:
We have a
File
in datamodel:I want to add a calculated field
url
, that will generate a public link to storage (private s3-comaptible cloud)So my application schema contains:
And resolver:
Fail is that this will only work if client will request both url and path, because otherwise response from Prisma simply will not contain path, because it contains only requested fields.
As a workaround one can manually request all fields in resolver, but this just kills the entire idea of Prisma and bindings, also gives a lot of problems handling relations
The text was updated successfully, but these errors were encountered: