Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

[WIP] Support enums #244

Merged
merged 22 commits into from
Nov 7, 2018
Merged

[WIP] Support enums #244

merged 22 commits into from
Nov 7, 2018

Conversation

Weakky
Copy link
Contributor

@Weakky Weakky commented Nov 2, 2018

  • Implements a proper TS/Flow parser to be able to make valuable comparisons between GraphQL and Model types.

  • Support Enum as scalar values (GraphQL enums are always inlined in graphqlgen.ts)

  • Support smart code generation/scaffolding:

Given the following GraphQL types:

type User {
  id: String!
  penColor: Color!
}

enum Color {
  RED
  GREEN
  BLUE
}

and the following model type:

type User {
  id: string
  penColor: ModelColor
}

the resolver for the penColor field will be generated as a defaultResolver if:

  • ModelColor is a subset or has the same values as Color. That is to say if ModelColor is of type:
    • type ModelColor = 'RED'
    • type ModelColor = 'BLUE'
    • type ModelColor = 'GREEN'
    • type ModelColor = 'RED' | 'BLUE'
    • type ModelColor = 'RED' | 'GREEN'
    • type ModelColor = 'BLUE' | 'GREEN'
    • type ModelColor = 'RED' | 'BLUE' | 'GREEN' etc..

or if penColor is of type:

  • penColor: 'RED'
  • penColor: 'BLUE'
  • penColor: 'GREEN'
  • penColor: 'RED' | 'BLUE'
  • penColor: 'RED' | 'GREEN'
  • penColor: 'BLUE' | 'GREEN'
  • penColor: 'RED' | 'BLUE' | 'GREEN' etc..

@@ -141,8 +142,7 @@ export namespace PostResolvers {
export namespace UserResolvers {
export const defaultResolvers = {
id: (parent: User) => parent.id,
name: (parent: User) =>
parent.name === undefined || parent.name === null ? null : parent.name,
name: (parent: User) => (parent.name === undefined ? null : parent.name),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why () is needed here?

Copy link
Contributor Author

@Weakky Weakky Nov 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parenthesis aren't in the code generator. They must be added by prettier somehow 😕

packages/graphqlgen/src/generators/common.ts Outdated Show resolved Hide resolved
@schickling
Copy link
Contributor

I've released a first version which can be installed via graphqlgen@beta. Please report if you run into any problems 🙏

@schickling schickling merged commit 404ad93 into master Nov 7, 2018
@Weakky Weakky deleted the feature/enums-support branch November 8, 2018 16:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants