json-graphql-server icon indicating copy to clipboard operation
json-graphql-server copied to clipboard

Why not Input Types?

Open frederikhors opened this issue 4 years ago • 4 comments

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.

frederikhors avatar Dec 31 '19 11:12 frederikhors

I agree it would be nice to use be able to extend a common inputType for all List method parameter of entities.

mbaroukh avatar Apr 20 '20 11:04 mbaroukh

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!

Kmaschta avatar Apr 22 '20 08:04 Kmaschta

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 and input of entity input type
  • [x] Made all create and update 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 avatar Aug 14 '20 15:08 M1chaelTran

@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 ?

draqist avatar Jul 10 '22 23:07 draqist