-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
[BUG] Cannot accept/send array using input type / input plugin #1269
Comments
Not sure whats going on here, can you share the generated GraphQL schema. Part of the issue with types is that the prisma utils plugin claims to return the full create input with the required relation properties, but the validation schema can't validate that (since they aren't actually part of the input). Working around this would require significantly better type inference for the prisma input fields, which isn't likely to be added soon. I am not clear on whats happening with the runtime error. Is the issue that the input is being converted from an array to an object, or is the prisma error just rendering it that way?
I don't know what this means, what is the input plugin, and where is it "expecting" and keyless object? having the GraphQL schema output, and the JSON version of the input args received in the resolver might help clarify what the issue is here |
UP The problem is partially solved, and it was my mistake.
As I understand point 3 is difficult to fix now, because of the complexity of type casting. |
Glad you got this figured out
If I am understanding this correctly, I think it might be a GraphQL issue, GraphQL automatically allows list inputs to be passed as an object, which it will treat as an list with 1 item, but it also shouldn't cause any issues
I think impossible might be an exaggeration here, I think if you do |
const CreateUserInput = builder.prismaCreate('User', {
fields: () => ({
email: 'String',
name: 'String',
posts: CreateUserPostsInput,
}),
});
const CreateUserPostsInput = builder.prismaCreateRelation('User', 'posts', {
fields: () => ({
create: CreateUserPostInput,
}),
});
const CreateUserPostInput = builder.prismaCreate('Post', {
name: 'CreateUserPostsInput',
fields: () => ({
title: 'String',
}),
});
builder.mutationType({
fields: (t) => ({
createUser: t.prismaField({
type: 'User',
args: {
data: t.arg({ type: CreateUserInput, required: true }),
},
resolve: (query, _, args) => prisma.user.create({ ...query, data: args.data }),
}),
}
}) mutation {
createUser(data: {
name: "test"
email: "test@test.com"
posts: {
create: [{
title: "post 1"
}, {
title: "post 2"
}]
}
}) {
id
posts {
title
}
}
} |
I don't know why, but if you make an inputType that is an array (list) the input plugin just ignores it, expecting a keyless object :)
Even if you specify array literals directly in the mutation, it still, converts that to an object, for some unknown reason
Even when trying to do a validation scheme, it doesn't like it. Below is the full code.
And yes, I can choose not to send an array, and the input plugin is fine with that, although it's very strange.
Mutation:
The text was updated successfully, but these errors were encountered: