Skip to content
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

Add support of wildcard fields #147

Closed
koistya opened this issue Mar 7, 2016 · 2 comments
Closed

Add support of wildcard fields #147

koistya opened this issue Mar 7, 2016 · 2 comments

Comments

@koistya
Copy link

koistya commented Mar 7, 2016

One use case that comes to mind is form validation, for example:

GraphQL Query

mutation {
  createUser(email: "[email protected]", password: "Passw0rd") {
    state: {
      isValid,
      errors*                   <-- here
    },
    user {
      id,
      email,
      emailVerified
    }
  }
}

GraphQL Response

{
  data: {
    state: {
      isValid: false,
      errors: {
        '': [
          'Failed to create a new user account.'
        ],
        email: [
          'User with this email address ([email protected]) already exists.'
        ]
      },
    },
    user: null
  }
}

Ref #117, graphql/graphql-js#44

@dylanahsmith
Copy link
Contributor

You can define your error type to have fieldName and message fields so that you don't need support for a wildcard. That would also allow your schema to evolve in case you want to attach more information to an error, like an error code.

👎 to having wildcards, since that also opens a huge can of worms about what is being returned, especially if the wildcard matches fields with arguments or object types with back-references, etc.

@dschafer
Copy link
Contributor

You can define your error type to have fieldName and message fields so that you don't need support for a wildcard. That would also allow your schema to evolve in case you want to attach more information to an error, like an error code.

Yep, I like this approach a lot; that's what I would recommend doing.

#127 contains more discussion about wildcard and why we chose not to include them. Between using fragments and @dylanahsmith's approach to situations like the one you describe, we've found that they tend not to be needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants