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

Bug: Accept empty types in GraphQL schemas #507

Closed
krisbitney opened this issue Oct 15, 2021 · 0 comments
Closed

Bug: Accept empty types in GraphQL schemas #507

krisbitney opened this issue Oct 15, 2021 · 0 comments
Labels
type: bug Something isn't working
Projects

Comments

@krisbitney
Copy link
Contributor

krisbitney commented Oct 15, 2021

We should consider allowing the usage of empty types to support polymorphism.

For example, let's say I want this:

type Action { }
type CreateAccount implements Action { }
type DeployContract implements Action { 
  code: Bytes! 
}

Right now I'm required to do something like this:

type Action { 
  _: String
}

type CreateAccount implements Action { 
  _: String 
}

type DeployContract implements Action { 
  code: Bytes! 
}

Also note the _ placeholders propagate to generated TypeScript types.

Here is an example exception thrown when attempting to use empty types:

$ npx w3 plugin codegen
✔ Manifest loaded from ./web3api.plugin.yaml
✖ Failed to generate types: Syntax Error: Expected Name, found "}".
GraphQLError [Object]: Syntax Error: Expected Name, found "}".
    at syntaxError (/Users/kris/WebstormProjects/monorepo/node_modules/graphql/error/syntaxError.js:15:10)
    at Parser.expectToken (/Users/kris/WebstormProjects/monorepo/node_modules/graphql/language/parser.js:1413:40)
    at Parser.parseName (/Users/kris/WebstormProjects/monorepo/node_modules/graphql/language/parser.js:98:22)
    at Parser.parseFieldDefinition (/Users/kris/WebstormProjects/monorepo/node_modules/graphql/language/parser.js:879:21)
    at Parser.optionalMany (/Users/kris/WebstormProjects/monorepo/node_modules/graphql/language/parser.js:1503:28)
    at Parser.parseFieldsDefinition (/Users/kris/WebstormProjects/monorepo/node_modules/graphql/language/parser.js:868:17)
    at Parser.parseObjectTypeDefinition (/Users/kris/WebstormProjects/monorepo/node_modules/graphql/language/parser.js:812:23)
    at Parser.parseTypeSystemDefinition (/Users/kris/WebstormProjects/monorepo/node_modules/graphql/language/parser.js:708:23)
    at Parser.parseDefinition (/Users/kris/WebstormProjects/monorepo/node_modules/graphql/language/parser.js:150:23)
    at Parser.many (/Users/kris/WebstormProjects/monorepo/node_modules/graphql/language/parser.js:1523:26) {
  locations: [ { line: 122, column: 1 } ]
}

Interestingly, this is in the same schema and appears to build without any problems. I actually get the opposite behavior: when I try to add the _ field to the child type, I get an exception complaining about duplicate fields in the type.

type AccessKeyPermission {
  _: String
}

type FullAccessPermission implements AccessKeyPermission {}
@krisbitney krisbitney added the type: bug Something isn't working label Oct 15, 2021
@nerfZael nerfZael linked a pull request Oct 21, 2021 that will close this issue
@dOrgJelli dOrgJelli added this to Done in Core Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
No open projects
Core
  
Done
Development

Successfully merging a pull request may close this issue.

2 participants