Skip to content

GraphQL can be less strict and complicated #932

Open
@moshest

Description

@moshest

I'm a software engineer for almost 20 years and I recently started using GraphQL extensively.

While I understand the original thoughts of making GraphQL as simple as possible, we end up with a language that's too complicated to handle taking too much control out from the user.

For instance:

  1. Object type seems redundant, we can just use interfaces instead:
interface Query {
  tasks: [Task!]!
}

interface Task {
  name: String!
  done: Boolean
}
  1. input types are just making everything more complicated and harder to share the same interfaces between inputs and outputs. It's better to define a workaround for field input with arguments than making everything duplicated with input types (Ie. ignore fields with arguments on inputs or allow a way to provide field arguments on input queries as well).
interface Mutation {
  addTask(data: TaskData!): Task!
}

interface TaskData {
  name: String!
}

interface Task implements TaskData {
  name: String!
  done: Boolean!
}
  1. In most of my schemas, I end up make more fields as required than I have optional fields. It will be much better to reverse the type system and allow mark only the optional fields instead:
interface Query {
  tasks: [Task]
}

interface Task {
  name: String
  done: Boolean?
}
  1. Adding recursion support for queries: Same as SQL let you run queries that can overwhelm the server, I think GraphQL should enable the same and let the user handle the consequences. Security concerns should only apply on the server implementation and not restrict language abilities.
interface TreeNode {
  label: String
  children: [TreeNode]
}

query {
  getTree {
    ...Node
  }
}

fragment Node on TreeNode {
  label
  children {
    ...TreeNode @RecursionLimit(100)
  }
}

I understand that this may not be the best place to communicate my thoughts but all of those points are shared across the internet with many StackOverflow and questions from frustrated users. If at least a few more people will see and agree with me then we can start pushing for a change in the proper channels.

We love GraphQL, we just want to make it better ❤️

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions