-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Overwriting GraphQL schema #1232
Comments
The issue seems to be about any resolver as a single string value, this will fail in // GraphQL.js
const schema = makeExecutableSchema({
typeDefs,
resolvers,
}); because it's literally not a function (in this image, I moved away from trying to rewrite practice which may be another problem, and just trying to create a simple new GraphQL endpoint) Although, this is how the docs say it should work https://strapi.io/documentation/guides/graphql.html Strangely, changing just the resolver does work, but this is not what I need to do module.exports = {
resolver: {
Query: {
practice: {
description: 'Return the practice of the authenticated user',
resolver: 'Practice.findMine'
},
practices: false
}
}
}; |
Hey @raulriera I was looking for this bug today and you right, the problem is when you add a @lauriejim : FYI =>
I try to replace it by:
But i have some problems with the override from the |
Hello guys @raulriera and @johannpinson ! @Aurelsicoko is the best person to help you on this side - but he has lot of work actually :/ Check out the contributing guide to get started: https://github.com/strapi/strapi/blob/master/.github/CONTRIBUTING.md |
Okay, so I fixed this. You can set the resolver in two different way: module.exports = {
definition: ``,
query: `
practice: [Practice]
`,
type: {
Practice: false
},
resolver: {
Query: {
practice: {
description: 'Return the practice of the authenticated user',
resolver: 'Practice.findMine'
},
practices: false
}
}
}; or with an object when you have to reach a controller's action which is inside a plugin module.exports = {
definition: ``,
query: `
user: [UsersPermissionsUser]
`,
type: {
UsersPermissionsUser: false
},
resolver: {
Query: {
user: {
description: 'Return the authenticated user',
resolver: {
plugin: 'users-permissions',
handler: 'User.findMe'
},
users: false
}
}
}; |
Oh, that is awesome @Aurelsicoko ... looking at your commit now... |
Not sure it will be the last one but it works for this case and it also supports the |
Thanks @Aurelsicoko! 👍 |
@Aurelsicoko I found that if i call in resolver default (autogenerated) functions from api/mymodel/controllers/mymodel.js, for example "find: async (ctx)"
it works fine, but if i create custom function, for example "getPacks" (even with the same code that default "find: async (ctx)" function) - i getting an error "TypeError: Pack.getPacks is not a function". Is it means that i can't call custom functions? |
It means that you have to create the custom functions in your controller, then make a reference to it. @alexandrebodin did you write a test about this use case or not? |
@Aurelsicoko Nope I only tested the generate api not the way we generate / overwrite it for now |
How to make a reference (in which directory/file)? Is there information in docs about it? |
You can find som examples here https://strapi.io/documentation/3.x.x/guides/graphql.html#customise-the-graphql-schema |
Hello, When I try within a custom schema.graphql within api/puppies/config
No errors. The Query does give me the console.log from with the results. api/puppies/controller/Puppies.js
|
Since it didnt gave me an error it solved it with good luck and checking the defined types within the playground.. updatePuppies->updatePuppiesPayload It would be a great help if a section would be added to help, where the documentation only shows how to extend a current mutation, since al created contenttypes has Payload within their Schema
|
@merijnponzo I'm not sure to understand but you weren't able to override the default generate mutation |
Informations
What is the current behavior?
I'm trying to overwrite the GraphQL query from
to
But running strapi will error in
Error: Resolver Query.practice must be object or function
Steps to reproduce the problem
Try to overwrite the default
findOne
route of any model like the example aboveWhat is the expected behavior?
It should overwrite the schema without a problem, even the generated code looks correct
Suggested solutions
I don't know any, I'm trying to find a solution myself without success
The text was updated successfully, but these errors were encountered: