Skip to content

Releases: cuongndc/hera

GraphQL enum case

31 Jan 10:37
c23f9d7
Compare
Choose a tag to compare

hera

πŸ‘©πŸΌβ€πŸ’» Simple and lightweight GraphQL client.

All Contributors
Build Status
npm
david
Hits-of-Code
GitHub

🧰 installation

yarn add hera-js

🌳 usage

import { hera } from 'hera-js';

const { data } = await hera({
  options: {
    url: 'https://example.com'
  },
  query: `
    query {
      user(id: $id) {
        id
        name
        age
      }
    }
  `,
  variables: {
    id: 1
  }
});

πŸ‘» passing parameters as objects

const { data } = await hera({
  options: {
    url: 'https://example.com',
  },
  query: `
    mutation {
      createUser(info: $info) {
        id
        name
        age
        address
        job
      }
    }
  `,
  variables: {
    info: {
      name: 'Cuong Tran',
      age: 22,
      address: 'Tam Ky - Sai Gon / Vietnam',
      job: 'software engineer',
    },
  },
});

πŸ› error handling

const { data, errors } = await hera({
  options: {
    url: 'https://example.com',
  },
  query: `
    query {
      user(id: $id) {
        id
        name
        age
      }
    }
  `,
  variables: {
    id: 1,
  },
});

🌏 global options

You can specify config defaults that will be applied to every request.

import { hera, globalOptions } from 'hera-js';

globalOptions.url = 'https://example.com';
// globalOptions.headers = <your headers>

const { data } = await hera({
  query: `
    mutation {
      createUser(info: $info) {
        id
        name
        age
        address
        job
      }
    }
  `,
  variables: {
    info: {
      name: 'Cuong Tran',
      age: 22,
      address: 'Sai Gon / Vietnam',
      job: 'software engineer',
    },
  },
});

πŸ’© enums

const { data } = await hera({
  query: `
    mutation {
      createUser(info: $info) {
        id
        name
        age
        address
        job
        sex
      }
    }
  `,
  variables: {
    info: {
      name: 'Cuong Tran',
      age: 22,
      address: 'Sai Gon / Vietnam',
      job: 'software engineer',
      sex: 'MALE',
    },
  },
  options: {
    enums: ['sex'],
  },
});

πŸš€ API

interface Options {
  url?: string;
  headers?: any;
  timeout?: number;
  enums?: string[];
}

hera({
  query: string;
  variables?: any;
  options?: Options;
}) : Promise<{ data: any; errors: any[] }>

πŸ“ options

{
  // `url` is the server URL that will be used for the request
  url: '/example',
  // `headers` are custom headers to be sent
  headers: {
    token: 'Fv0761DZcunUr0dKBc4oo5k55jJchwqu',
    'Content-Type': 'application/json'
  },
}

πŸ“’ query

query is query or mutation in Graphql

graphql's query

query: `
  query {
    user(id: $id) {
      id
      name
      age
    }
  }
`

graphql's mutation

query: `
  mutation {
    createUser(info: $info) {
      id
      name
      age
      address
      job
    }
  }
`

πŸ’‰ variables

variables is used to pass values to query's variables

query: `
  mutation {
    createUser(info: $info) {
      id
      name
      age
      address
      job
    }
  }
`,
variables: {
  info: {
    name: 'Cuong Tran',
    age: 22,
    address: 'Sai Gon / Vietnam',
    job: 'software engineer',
  },
}

🀝 contributors

Thanks goes to these wonderful people (emoji key):

Cuong Duy Nguyen
Cuong Duy Nguyen

πŸ’» πŸ“– ⚠️ πŸ‘€

This project follows the all-contributors specification. Contributions of any kind welcome!

πŸ“œ license

MIT Β© Cuong Tran

Expose formatQuery

07 Nov 06:46
db15095
Compare
Choose a tag to compare
v0.5.0

feat: expose formatQuery (#33)

support timeout

09 Sep 03:57
b3157c0
Compare
Choose a tag to compare

πŸš€ API

interface Options {
  url?: string;
  headers?: any;
  timeout?: number;
}

hera({
  query: string;
  variables?: any;
  options?: Options;
}) : Promise<{ data: any; errors: any[] }>

support global options

09 Aug 09:13
1b53a96
Compare
Choose a tag to compare

hera

πŸ‘©πŸΌβ€πŸ’» Simple and lightweight GraphQL client.

All Contributors
Build Status
npm
david
Hits-of-Code
GitHub

🧰 installation

yarn add hera-js

🌳 usage

import { hera } from 'hera-js';

const { data } = await hera({
  options: {
    url: 'https://example.com'
  },
  query: `
    query {
      user(id: $id) {
        id
        name
        age
      }
    }
  `,
  variables: {
    id: 1
  }
});

πŸ‘» passing parameters as objects

const { data } = await hera({
  options: {
    url: 'https://example.com'
  },
  query: `
    mutation {
      createUser(info: $info) {
        id
        name
        age
        address
        job
      }
    }
  `,
  variables: {
    info: {
      name: 'Cuong Tran',
      age: 22,
      address: 'Sai Gon / Vietnam',
      job: 'software engineer'
    }
  }
});

πŸ› error handling

const { data, errors } = await hera({
  options: {
    url: 'https://example.com'
  },
  query: `
    query {
      user(id: $id) {
        id
        name
        age
      }
    }
  `,
  variables: {
    id: 1
  }
});

🌏 global options

You can specify config defaults that will be applied to every request.

import { hera, globalOptions } from 'hera-js';

globalOptions.url = 'https://example.com';

const { data } = await hera({
  query: `
    mutation {
      createUser(info: $info) {
        id
        name
        age
        address
        job
      }
    }
  `,
  variables: {
    info: {
      name: 'Cuong Tran',
      age: 22,
      address: 'Sai Gon / Vietnam',
      job: 'software engineer'
    }
  }
});

πŸš€ API

hera({
  query: string;
  variables?: any;
  options?: Options;
}) : Promise<{ data: any; errors: any[] }>

πŸ“ options

{
  // `url` is the server URL that will be used for the request
  url: '/example',
  // `headers` are custom headers to be sent
  headers: {
    token: 'Fv0761DZcunUr0dKBc4oo5k55jJchwqu',
    'Content-Type': 'application/json'
  }
}

πŸ“’ query

query is query or mutation in Graphql

graphql's query

query: `
  query {
    user(id: $id) {
      id
      name
      age
    }
  }
`

graphql's mutation

query: `
  mutation {
    createUser(info: $info) {
      id
      name
      age
      address
      job
    }
  }
`

πŸ’‰ variables

variables is used to pass values to query's variables

query: `
  mutation {
    createUser(info: $info) {
      id
      name
      age
      address
      job
    }
  }
`,
variables: {
  info: {
    name: 'Cuong Tran',
    age: 22,
    address: 'Sai Gon / Vietnam',
    job: 'software engineer'
  }
}

🀝 contributors

Thanks goes to these wonderful people (emoji key):

Cuong Duy Nguyen
Cuong Duy Nguyen

πŸ’» πŸ“– ⚠️ πŸ‘€

This project follows the all-contributors specification. Contributions of any kind welcome!

πŸ“œ license

MIT Β© Cuong Tran

support error handling

09 Aug 05:29
176a8d0
Compare
Choose a tag to compare

hera

πŸ‘©πŸΌβ€πŸ’» Simple and lightweight GraphQL client.

All Contributors
Build Status
npm
david
Hits-of-Code
GitHub

🧰 installation

yarn add hera-js

🌳 usage

import { hera } from 'hera-js';

const { data } = await hera({
  option: {
    url: 'https://example.com'
  },
  query: `
    query {
      user(id: $id) {
        id
        name
        age
      }
    }
  `,
  variables: {
    id: 1
  }
});

πŸ‘» passing parameters as objects

const { data } = await hera({
  option: {
    url: 'https://example.com'
  },
  query: `
    mutation {
      createUser(info: $info) {
        id
        name
        age
        address
        job
      }
    }
  `,
  variables: {
    info: {
      name: 'Cuong Tran',
      age: 22,
      address: 'Sai Gon / Vietnam',
      job: 'software engineer'
    }
  }
});

πŸ› error handling

const { data, errors } = await hera({
  option: {
    url: 'https://example.com'
  },
  query: `
    query {
      user(id: $id) {
        id
        name
        age
      }
    }
  `,
  variables: {
    id: 1
  }
});

πŸš€ API

hera({
  option: Option;
  query: string;
  variables?: any;
}) : Promise<{ data: any; errors: any[] }>

πŸ“ options

{
  // `url` is the server URL that will be used for the request
  url: '/example',
  // `headers` are custom headers to be sent
  headers: {
    token: 'Fv0761DZcunUr0dKBc4oo5k55jJchwqu',
    'Content-Type': 'application/json'
  }
}

πŸ“’ query

query is query or mutation in Graphql

graphql's query

query: `
  query {
    user(id: $id) {
      id
      name
      age
    }
  }
`

graphql's mutation

query: `
  mutation {
    createUser(info: $info) {
      id
      name
      age
      address
      job
    }
  }
`

πŸ’‰ variables

variables is used to pass values to query's variables

query: `
  mutation {
    createUser(info: $info) {
      id
      name
      age
      address
      job
    }
  }
`,
variables: {
  info: {
    name: 'Cuong Tran',
    age: 22,
    address: 'Sai Gon / Vietnam',
    job: 'software engineer'
  }
}

Contributors

License

MIT Β© Cuong Tran

rename giin πŸ¦„ to hera πŸ‘©πŸΌ

13 Jul 18:55
cb8c638
Compare
Choose a tag to compare

πŸ¦„ giin v0.1.1

30 Dec 17:54
5a61684
Compare
Choose a tag to compare

πŸ¦„ Have a Graphql client's feature: query and mutation

import { giin } from 'giin';
// const { giin } = require('giin');
giin({
  option: {
    url: 'https://example.com'
  },
  query: `
    query {
      user(id: $id) {
        id
        name
        age
      }
    }
  `,
  variables: {
    id: 1
  }
});

πŸ‘» Special 🚧: giin allows passing parameters as objects.

giin({
  option: {
    url: 'https://example.com'
  },
  query: `
    query {
      user(info: $info) {
        id
        name
        sex
        age
        address
        job
      }
    }
  `,
  variables: {
    info: {
      name: 'Cuong Duy Nguyen',
      address: 'Ho Chi Minh'
    }
  }
});