Code Monkey home page Code Monkey logo

Comments (3)

hairyhenderson avatar hairyhenderson commented on August 17, 2024

Hi @miko, thanks for filing this.

Do you have a specific use for accessing GraphQL datasources with gomplate?

One particular problem with GraphQL (as opposed to more traditional RESTful APIs) is the somewhat complex request body necessary to make almost any query. With a RESTful API, you can treat the remote endpoint like a filesystem, where the GET method is conceptually similar to a regular read operation. But with GraphQL, all queries (as far as I know?) are POSTs, and require bodies. I'm not sure how it would be possible to model that as a datasource in URL form, which is a strict necessity for gomplate.

Does this make sense, or am I missing some obvious simpler usage here?

from gomplate.

miko avatar miko commented on August 17, 2024

GraphQL queries can be transmitted by HTTP either as POST or GET request, as specified here:
https://graphql.org/learn/serving-over-http/

There are (read-only) queries and (possibly read-write) mutations (add, update, delete), so I mean queries as datasources (both by GET or POST).

Example graphql query using GET:

curl -v 'https://countries.trevorblades.com/graphql?query=\{countries\{name\}\}'

(but some graphql servers may block the GET method, even if required by specifiaction)

Example graphql query using POST:

curl --request POST \
    --header 'content-type: application/json' \
    --url 'https://spacex-production.up.railway.app/' \
    --data '{"query":"query ExampleQuery($limit: Int) {\nships (limit:$limit){\n  name\n}\n}","variables":{"limit":2}}'

For simple cases (like the first query above) you could use a http datasource, but the real help would be if for the second case I could use something similar to:

gomplate -d foo=graphql+POST://spacex-production.up.railway.app/' --query '{ships (limit:$limit){name}}' --variables '{"limit":2}'

gomplate -d foo=graphql+POST://spacex-production.up.railway.app/' --queryfile  ./ships.graphql --variables '{"limit":2}'

from gomplate.

hairyhenderson avatar hairyhenderson commented on August 17, 2024

Thanks for the response @miko. Like I said above, this would be a significant departure from how gomplate works with datasources today. Datasources are modelled internally as filesystems accessed purely through URLs, and so passing in a large query body and set of variables seems like it just wouldn't work conceptually.

Being a query language, GraphQL is much more akin to SQL (which gomplate also can't support) than a filesystem layer on top of a key-value storage back-end.

As such, I think the answer this feature is going to have to be "no" (at least, not yet).

I'm going to close the issue, but feel free to comment further, or start up a discussion if you can see a reasonable approach that could fit elegantly within gomplate's operational model.

from gomplate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.