DEV Community

Discussion on: I made a fetch-wrapper for making graphql api calls!

Collapse
 
qm3ster profile image
Mihail Malo

It would be more concise to take these non-optional parameters as arguments:
jraph(url, query[, {...options}]):

jraph("https://csb-xpwq1o2824-xravvsjkul.now.sh/graphql",
    `query{
         items{
             title
         }
     }`
)

But, I feel like taking (url)(query) would be more ergonomic, for reuse:

const graphql = jraph("https://csb-xpwq1o2824-xravvsjkul.now.sh/")

const res1 = graphql(
    `query{
         items{
             title
         }
     }`
)
const res2 = graphql(
    `query{
         🅱tems{
             title
         }
     }`
)

Maybe return a Template Tag?

const graphql = jraph("https://csb-xpwq1o2824-xravvsjkul.now.sh/")

const res = graphql`
    query{
        🅱tems{
            👌itle
        }
    }`
Collapse
 
ianfabs profile image
Ian Fabs

That’s actually exactly what I was planning to do. I’m glad i got some positive feedback on that kind of syntax. I’ll publish the new syntax tomorrow!