Replies: 5 comments
-
Maybe we need to specify in mutation that it's an array ? |
Beta Was this translation helpful? Give feedback.
-
what's specify in mutation how to create that ? |
Beta Was this translation helpful? Give feedback.
-
Your definition should be same as server\s definition. E.g., in server
Request must be something like this:
|
Beta Was this translation helpful? Give feedback.
-
In case you want to pass an array of objects this is how I did it. In your server export const OptionInputType = new GraphQLInputObjectType({
name: 'OptionInput',
fields: () => ({
option_uid: { type: GraphQLID },
attribute_uid: { type: GraphQLID },
option_name: { type: GraphQLString },
additional_price: { type: GraphQLFloat },
color_hex: { type: GraphQLString },
}),
});
// -------------
const Mutation = new GraphQLObjectType({
name: 'Mutation',
fields: {
CreateAttribute: {
type: AttributeType,
args: {
product_uid: { type: GraphQLID },
attribute_name: { type: GraphQLString },
options: { type: new GraphQLList(OptionInputType) },
},
async resolve(
parent,
{ product_uid, attribute_name, options }
) {
console.log(`====>`, { product_uid, attribute_name, options })
return []
},
}}
}) In Client import { gql } from 'graphql-request';
export const CreateAttributeMutation = gql`
mutation CreateAttribute(
$product_uid: ID!
$attribute_name: String!
$options: [OptionInput!]!
) {
CreateAttribute(
product_uid: $product_uid
attribute_name: $attribute_name
options: $options
) {
attribute_name
}
}
`; |
Beta Was this translation helpful? Give feedback.
-
Thank you very much, this successfully solved my problem |
Beta Was this translation helpful? Give feedback.
-
Hey, thx for the awesome project!
I'm a graphql-request beginner and like to ask, if it is possible to insert multiple objects at once with graphql-request using variables and how it should look like.
I was able to successful insert a single entity like that:
But when changing the variables to an array i got an error.
Can someone give me a hint into the right direction here? Thx in advance!
Beta Was this translation helpful? Give feedback.
All reactions