Khan / genqlient

a truly type-safe Go GraphQL client
MIT License
1.07k stars 107 forks source link

Generate custom struct tags #234

Open nettrino opened 1 year ago

nettrino commented 1 year ago

Is your feature request related to a problem? Please describe.

I would like to generate types from a graphql schema with neo4j graphql directives, and convert those to gogm-compatible struct tags.

For instance:

Example of graphql with neo4j directives:

  interface ResourceEntity {
    id: ID! @id(autogenerate: false)
    name: String
  }

  type Resource implements ResourceEntity {
    id: ID! @id(autogenerate: false)
    name: String
    containedBy: [ResourceEntity!]! @relationship(type: "CONTAINS", direction: IN)
  }

Describe the solution you'd like

Example of generated code:

type ResourceEntity struct {
    // provides required node fields
    gogm.BaseNode

    Name         string                `gogm:"name=name"`
}

type Resource struct {
    // provides required node fields
    gogm.BaseNode

    Name  string     `gogm:"name=name"`
    ContainedBy  []*ResourceEntity   `gogm:"direction=incoming;relationship=..."`
}

Would be helpful to even pass a json/yaml or have an annotation-based approach to define struct tags for the different directives

Describe alternatives you've considered I can manually parse graphql and emit struct_tags of appropriate types for gogm

benjaminjkraft commented 1 year ago

Interesting. This looks complex enough I think we'd need to do it as some sort of plugin (or maybe even two, one for neo4j and one for gogm). I've created #237 to track setting up a plugin API; it will require some careful design.