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

support .gqlgen.yml #163

Merged
merged 4 commits into from
Jul 5, 2018
Merged

support .gqlgen.yml #163

merged 4 commits into from
Jul 5, 2018

Conversation

vvakame
Copy link
Collaborator

@vvakame vvakame commented Jul 2, 2018

refs #161
I'm implemented types.yaml support 👍

Now, We can processing 3 forms of types.* file.

old one.

{
    "Element": "github.com/vektah/gqlgen/test.Element"
}

JSON form.

{
    "Element": {
        "entityPath": "github.com/vektah/gqlgen/test.Element"
    }
}

YAML form.

- typeName:   Element
  entityPath: github.com/vektah/gqlgen/test.Element

If json is used it may be better to display an error to use yaml.

@vvakame
Copy link
Collaborator Author

vvakame commented Jul 2, 2018

👀 vvakame@26f865b

- typeName:   User
  entityPath: remote_api.User
  fields:
  - fieldName: likes
    resolver:  true

Copy link
Collaborator

@vektah vektah left a comment

Choose a reason for hiding this comment

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

I appreciate the PR but I think this needs a bit more thought.

I was picturing something more like

models:
    User: 
        model: github.com/my/pkg/user.User
        fields:
            ID: 
                resolver: true

Because the unique element (typeName, fieldName) are keys, linters will fail on dupes.

Also if we head down this path I think we should just deprecate (and provide command to convert) the old format to the new.

It probably probably becomes a more general .gqlgen.yml and should probably support setting all the command line args.

main.go Outdated
}

if strings.HasSuffix(*typemap, ".json") {
return loadTypeMapJSON()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yaml is a superset of json, so you should be able to remove the json codepath here entirely.

This also means you can use yaml comments in json files and leave on trailing newlines I think.

@vvakame
Copy link
Collaborator Author

vvakame commented Jul 3, 2018

@vektah thank for advice!

I added support about .gqlgen.yml.

schema: schema.graphql
output: generated.go
modeloutput: models/generated.go

models:
  Element:
    model: github.com/vektah/gqlgen/test.Element
  Viewer:
    model: github.com/vektah/gqlgen/test.Viewer
  User:
    model: remote_api.User

and, user use -typemap commandline option.
They will get the warning message likes below.

$ go run ../main.go -out generated.go -typemap types.json -models models/generated.go
you should use .gqlgen.yml with below content.

schema: schema.graphql
models:
  Element:
    model: github.com/vektah/gqlgen/test.Element
  User:
    model: remote_api.User
  Viewer:
    model: github.com/vektah/gqlgen/test.Viewer
output: generated.go
modeloutput: models/generated.go

@vvakame vvakame changed the title Add support types.yaml support .gqlgen.yml Jul 3, 2018
@vektah vektah merged commit f0a0861 into 99designs:master Jul 5, 2018
@vvakame vvakame deleted the feat-types-json branch July 5, 2018 05:27
cgxxv pushed a commit to cgxxv/gqlgen that referenced this pull request Mar 25, 2022
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

Successfully merging this pull request may close these issues.

2 participants