-
Notifications
You must be signed in to change notification settings - Fork 29
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
Remove field from InputType #34
Comments
Am I understanding correctly: You want to only be able to provide authorIs when creating a new book (which you can already do). But you want the GraphQL schema to prevent a user from sending a new author object when creating a book, which would result in that author being created then and there. Is that right? If so, no, as of now there's no way to remove the authors from the input type, but it's something I'd be willing to consider after version 0.8 comes out. |
Yes, it's exactly that. I already have an idea that works for a PR. I will submit so you can see it |
Cool |
Hey do me a favor, if you're looking to PR, please send it off the |
I'm considering using your library in one of my projects, and I have a couple more questions:
const newType = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
hello: {
type: GraphQLString,
resolve() {
return 'world';
},
},
},
});
export const Book = {
table: 'books',
fields: {
createdType: newType,
},
} What I really want with this is to be able to define an enum for graphql. I'm still getting to know the library code and I don't know what to do to accomplish these points. But with some guidance I can create a PR to have these 2 functionalities as well :) Thanks! |
Yeah the code is pretty horrible at the moment. Some major cleanup + TypeScript is on my ToDo list. Not sure how you'd do default values, or what that'd even mean, here. So right now whatever fields you request will be queried from Mongo. Your best bet might be the https://github.com/arackaf/mongo-graphql-starter#all-available-hooks I'm not sure what the GraphQL type does, but I do have the JSON type implemented, so common types can absolutely be baked in, here. Check out createMasterSchema.js, createMasterResolver.js and createTypeSchema in src/codeGen |
For the default values I was thinking something like: export const Book = {
table: 'books',
fields: {
fieldWithDefault: {
type: StringType,
defaultValue: "a good book"
},
},
}; And what would do is set the default value for the InputType. But maybe that's not the best approach.. Maybe it would be better to set default values for arguments in resolver and not in the Type itself. But that would be more complex.. The result would be: type BookInput {
_id: String
fieldWithDefault: String = "a good book"
} About the GraphQL type, it's just a easy way in graphql library to create and manage graphql Types. You can see it in use here https://github.com/graphql/graphql-js#using-graphqljs |
Default values in the input type is actually the only option that makes sense to me. I could then apply those defaults in the resolver for the create mutation. What would default values in the resolver do, specifically? Afraid I don't quite follow what you might be going for, there? |
I was thinking that adding to the input type would add to all the Resolvers, so you would have the update with the default value set.. But only adding to the create resolver, like you said, makes sense and solves that :) |
I have this 2 types that have a relation between them.
What I want is to give the user the possibility to when getting a book, to also get the author of that book. But when creating a book, only send the authorsIds array of that book.
Is there an option so that I can remove a field from the Input type? And only from the Input Type?
The end result should be:
The text was updated successfully, but these errors were encountered: