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

[Feature reqeust] Add possiblity to load query from string / .gql file #66

Open
karolzlot opened this issue Feb 4, 2021 · 4 comments
Open

Comments

@karolzlot
Copy link

I see that currently this library requires every query to be a "golang type".

It is not possible to use graphql string (or file) with ready to use query.

I am generating queries in Hasura, so I really don't need to convert them do golang types, I think.

WDYT?

@dmitshur
Copy link
Member

The main reason they're a Go value is so that you can access the query response by using that Go value. Other approaches are certainly possible and can be explored. I don't have plans to work on this myself.

@karolzlot
Copy link
Author

karolzlot commented Feb 17, 2021

@dmitshur
I see your point.

I wonder about one thing: would it be possible to make transpiler which would convert GrapQL query to correct golang types? It seems to me that it is reapeatable work which can be automated, but I am not sure.

How do you think?

@dmitshur
Copy link
Member

dmitshur commented Feb 17, 2021

Yes, a GraphQL query → Go type tool (with a UI similar to https://mholt.github.io/json-to-go/; CC @mholt) is very possible and likely a good idea, as it'd help eliminate the manual work involved in those conversions. It would need a parser for GraphQL queries, and those exist now. I had this idea at the start of the project, but haven't had a chance to implement it myself. It'd be great if someone makes such a tool.

@StevenACoffman
Copy link

StevenACoffman commented Mar 13, 2021

While I would love a graphql-to-go for clients like gqlgen for servers, even if I had it now, there are some times I would like the option to bypass the struct tag solution for the outermost operation name and variable definitions in queries.

Specifically, I find that for long operation names and long lists of variable definitions, having that as a struct tag gets unwieldy (1024+ character go struct lines?).

I can dynamically alter the struct tag to load the query from a file, but I feel like there's probably something much simpler that could be exposed to facilitate this specific use case.

alexandear pushed a commit to alexandear/graphql that referenced this issue Jan 8, 2024
* docs: clarify usage of structs as variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants