-
Notifications
You must be signed in to change notification settings - Fork 35
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
How to retrieve DB context in a Mutation with extendWithMutations
#65
Comments
I have tried: import {
GraphQLObjectType,
GraphQLNonNull,
GraphQLInputType,
GraphQLInputObjectType,
GraphQLString,
GraphQLInt
} from 'graphql'
// import { CvU}
//...
export const CvUserType = new GraphQLObjectType({
name: 'CvUserType',
description: 'Use this object to create new cvUser',
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLInt),
description: 'Record ID',
},
first_name: {
type: new GraphQLNonNull(GraphQLString),
description: 'First Name',
},
last_name: {
type: new GraphQLNonNull(GraphQLString),
description: 'Last Name',
},
}),
})
export const CreateCvUserInputType = new GraphQLInputObjectType({
name: 'CreateCvUserInputType',
description: 'CvUser',
fields: () => ({
first_name: {
type: new GraphQLNonNull(GraphQLString),
description: 'First Name',
},
last_name: {
type: new GraphQLNonNull(GraphQLString),
description: 'Last Name',
},
}),
})
export function createCvUser (builder) {
const theBuilder = builder
return new GraphQLObjectType({
name: 'RootMutationType',
description: 'Domain API actions',
fields: () => ({
createCvUser: {
description: 'Creates a new cvUser',
type: CvUserType,
args: {
input: { type: new GraphQLNonNull(CreateCvUserInputType )},
},
resolve: (root, inputCvUser) => {
return theBuilder.insertAndFetch(inputCvUser.input)
},
},
}),
})
} but I get Please, even a slapped together answer will help! |
I notice in the Is this possibly a bug? |
Unsure if it is the same bug- but I haven't been able to get mutations working at all. I get the error- My query looks like this:
That query looks wrong to me. Any ideas on how it should look? |
it probably needs to look more like this: That will work, but even better, declare the |
Thanks @Trellian that got it working. Why is this example so verbose? Is there a way to write it simpler like the below example? This is how I'd write it if I wasn't using /schema.graphql
/resolvers.js
|
@yarnball no problem :) It can be done, as you say, without using an If you don't mind, would you please post your working code for reference? Other people will find it useful (especially me) :) |
@Trellian Sure, for my code I create a wrapper so I can easily pass it a set of options. Forgive the field names- they probably won't make total sense. I'm very open to feedback! Only issue I had with the below, is I cannot find a way to pass more than one mutation. I tried (without success):
So I pass it an object like this:
|
Hi @timhuff ,
Regarding mutations, I am ditching my embedded code approach and going with your excellent
extendWithMutations()
approach, but I have a couple of usage questions, please:extendWithMutations()
for mutations on multiple models? I have multiple mutations per model, and obviously multiple models with this need. Should I do:Do you perhaps have a simple example?
TIA,
Adrian
The text was updated successfully, but these errors were encountered: