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

Generated code imports own package (import cycle) #143

Closed
dabfleming opened this issue Jun 21, 2018 · 4 comments
Closed

Generated code imports own package (import cycle) #143

dabfleming opened this issue Jun 21, 2018 · 4 comments

Comments

@dabfleming
Copy link

There may be a way to avoid this using the package and modelpackage flags, but it isn't obvious to me.

My situation is I'm generating in the foo/bar/model package, and types.json includes "Form": "foo/bar/model.Form"

Expected Behaviour

Generator recognizes this is the destination package, does not attempt import.

Actual Behavior

generated.go includes import line: "foo/bar/model" resulting in import cycle.

@sylvain101010
Copy link

sylvain101010 commented Jun 22, 2018

a simple schema to reproduce the bug:

input Filter {
  offset: Int!
  limit: Int!
}

type Todo {
  id: String!
  text: String!
  author: User!
  # the default value cause the import cycle error
  events(filter: Filter = {offset: 0, limit: 25}): [Event!]!
}

@jonlundy
Copy link
Contributor

@z0mbie42 i filled in some of the missing items i see a interesting bug with Filter.

input Filter {
  offset: Int!
  limit: Int!
}

type Todo {
  id: String!
  text: String!
  author: User!
  # the default value cause a bug
  events(filter: Filter = {offset: 0, limit: 25}): [Event!]!
}

type User {
  name: String!
}

type Event {
  name: String!
}

type Query {
  todos: [Todo!]!
} 

generates the following:

			var tmp interface{} = map[string]interface{}{"offset":0"limit":25}

there is a missing comma between the offset and limit.

@vektah
Copy link
Collaborator

vektah commented Jun 23, 2018

Thanks for the defaults fix.

The import loop is less obvious, most of the examples work the way you're describing. eg https://github.com/vektah/gqlgen/blob/master/example/scalars/types.json#L2

I wonder if this is another case sensitivity issue, what OS are you running? Have you tried since #136?

A more complete example would be handy here.

@sylvain101010
Copy link

The simpler way to reproduce the error is using the following project:
https://github.com/z0mbie42/goes/blob/master/_examples/api
and replace https://github.com/z0mbie42/goes/blob/master/_examples/api/schema.graphql#L14

 events(filter: Filter): [Event!]!

by

events(filter: Filter = {offset: 0, limit: 25}): [Event!]!

But, after applying the patch #146 the code generate without error (no missing comma and no import cycle)

@vektah vektah closed this as completed Jun 29, 2018
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

4 participants