Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

sarkistlt/fetch-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple implementation of "fetch" for GraphQL API. Module use vanilla javaScript 'XMLHttpRequest', so it will work everywhere.

No polyfills, No dependencies, just 588 Bytes simple function.

Usage pretty similar to standard "fetch".

Install

npm i -S fetch-graph

##Description

import fetchGraph from 'fetch-graph';

fetchGraph(path, request[, variables])
// returns Promise
// path - your GraphQL API address
// request - string of same structure query as in GraphiQL tool
// variables - same logic as in GraphiQL tool

##Example

import fetchGraph from 'fetch-graph';

let request = `query getCategory($id: String!) {
                    getCategory(id: $id) {
                        id
                        name
                    }    
               }`;
              
variables = {id: '12345'};

fetchGraph('/graphql', request, variables)
            .then(res => console.log(res))
            .catch(console.error);
            
/* result
{
    data: {
        getCategory: [{itemObj}]
    }
}

License

MIT

About

Simple implementation of "fetch" for GraphQL API. No polyfills, No dependencies.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
Morty Proxy This is a proxified and sanitized view of the page, visit original site.