json-graphql-server
json-graphql-server copied to clipboard
Why not Input Types?
I need to understand why using the db.js
example file from Readme it doesn't generate the input PostInput
or input UserInput
or input CommentInput
.
Example:
I think it is better to use something like this:
createPost(id: ID!, input: PostInput!): Post
instead of what is now generated:
createPost(id: ID!, title: String!, views: Int!, user_id: ID!): Post
.
Am I wrong? I'm still learning... I'm asking for hints. Thanks.
I agree it would be nice to use be able to extend a common inputType for all List method parameter of entities.
This is a good idea, and it's closer to the real usage of GraphQL nowadays. But that will be a breaking change, so, let's keep that idea for later!
I did this and a little more on my fork if anyone is interested. Feel free to take whatever you need since my changes are breaking changes and I didn't bother to update the test or documentation. https://github.com/M1chaelTran/json-graphql-server/commit/b352efeb86beb16fa858997b4a64b02b1e8b95c3
Changes include:
- [x] Generate of Input type for each entity
- [x] Update now takes an
id
andinput
of entity input type - [x] Made all
create
andupdate
input fields optional (since this is a test/mock API, it is more convenient to have everything optional) - [x] Remove
all
prefix from Queries (this it is what I need for my project, so feel free to ignore this)
@M1chaelTran Do you know if there's a way i can achieve this in my own project, I'm taking an assessment for a job and i'd like to be able to pass variables as inputs to the query to use them as filter methods. Is there a way i can achieve this @slax57 ?