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

Name collision markdown formatting fixes #2335

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 55 additions & 23 deletions docs/content/reference/name-collision.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ as a composite of the Enum name and each individual value.
Currently, enum types are transposed as such:

```graphql
# graphql

enum MyEnum {
value1
value2
Expand All @@ -30,6 +32,8 @@ enum MyEnum {
Which will result in the following Golang:

```go
// golang

type MyEnum string

const (
Expand All @@ -44,20 +48,24 @@ However, those above enum values are just strings. What if you encounter a scen
necessary:

```graphql
# graphql

enum MyEnum {
value1
value2
value3
value4
Value4
Value_4
Value4
Value_4
}
```

The `Value4` and `Value_4` enum values cannot be directly transposed into the same "pretty" naming convention as their
resulting constant names would conflict with the name for `value4`, as so:

```go
// golang

type MyEnum string

const (
Expand All @@ -76,9 +84,9 @@ Which immediately leads to compilation errors as we now have three constants wit

1. Store each name generated as part of a run for later comparison
2. Try to coerce name into `CapitalCase`. Use if no conflicts.
- This process attempts to break apart identifiers into "words", identified by separating on capital letters,
underscores, hyphens, and spaces.
- Each "word" is capitalized and appended to previous word.
- This process attempts to break apart identifiers into "words", identified by separating on capital letters,
underscores, hyphens, and spaces.
- Each "word" is capitalized and appended to previous word.
3. If non-composite name, append integer to end of name, starting at 0 and going to `math.MaxInt`
4. If composite name, in reverse order, the pieces of the name have a less opinionated converter applied
5. If all else fails, append integer to end of name, starting at 0 and going to `math.MaxInt`
Expand All @@ -90,6 +98,8 @@ The first step to produce a name that does not conflict with an existing name su
### Example A
GraphQL:
```graphql
# graphql

enum MyEnum {
Value
value
Expand All @@ -99,31 +109,38 @@ enum MyEnum {
```
Go:
```go
// golang

type MyEnum string

const (
MyEnumValue MyEnum = "Value"
MyEnumvalue MyEnum = "value"
MyEnumTitleValue MyEnum = "TitleValue"
MyEnumtitle_value MyEnum = "title_value"
MyEnumValue MyEnum = "Value"
MyEnumvalue MyEnum = "value"
MyEnumTitleValue MyEnum = "TitleValue"
MyEnumtitle_value MyEnum = "title_value"
)
```

### Example B
GraphQL:
```graphql
# graphql

enum MyEnum {
TitleValue
title_value
title_Value
Title_Value
TitleValue
title_value
title_Value
Title_Value
}
```
Go:
```go
// golang

type MyEnum string

const (
MyEnumTitleValue MyEnum = "TitleValue"
MyEnumTitleValue MyEnum = "TitleValue"
MyEnumtitle_value MyEnum = "title_value"
MyEnumtitle_Value MyEnum = "title_Value"
MyEnumTitle_Value MyEnum = "Title_Value"
Expand All @@ -133,16 +150,21 @@ const (
### Example C
GraphQL:
```graphql
# graphql

enum MyEnum {
value
Value
value
Value
}
```
Go:
```go
// golang

type MyEnum string

const (
MyEnumValue = "value"
MyEnumValue = "value"
MyEnumValue0 = "Value"
)
```
Expand All @@ -157,33 +179,43 @@ Lets mutate [Example C](#example-c):
### Example C - State A
GraphQL:
```graphql
# graphql

enum MyEnum {
value
Value
value
Value
}
```
Go:
```go
// golang

type MyEnum string

const (
MyEnumValue = "value"
MyEnumValue = "value"
MyEnumValue0 = "Value"
)
```

### Example C - State B
GraphQL:
```graphql
# graphql

enum MyEnum {
Value
value
Value
value
}
```
Go:
```go
// golang

type MyEnum string

const (
MyEnumValue = "Value"
MyEnumValue = "Value"
MyEnumValue0 = "value"
)
```
Expand Down