GithubHelp home page GithubHelp logo

addon-graphql's Introduction

Storybook GraphiQL Addon

Storybook GraphQL Addon can be used to display the GraphiQL IDE with example queries in Storybook.

Framework Support

Screenshot

Getting Started

First, install the addon

yarn add @storybook/addon-graphql --dev

Import the setupGraphiQL function and use it to create the graphiql helper with a base url.

import { storiesOf } from "@storybook/react";
import { setupGraphiQL } from "@storybook/addon-graphql";

// setup the graphiql helper which can be used with the add method later
const graphiql = setupGraphiQL({ url: "http://localhost:3000/graphql" });

storiesOf("GraphQL Demo", module).add(
  "get user info",
  graphiql(`{
    user(id: "1") {
      name
    }
  }`)
);

Tip: try creating the helper in another file and import the configured graphiql helper from it

Advanced Setup

The setupGraphiQL function also accepts a fetcher parameter which can be used to change how graphiql gets data. If the fetcher parameter is not given, it'll create a fetcher which uses the fetch api to make requests. The above example can also be written using a custom fetcher.

import { storiesOf } from "@storybook/react";
import { setupGraphiQL } from "@storybook/addon-graphql";

import { url } from "./settings";

const fetcher = (params) => {
  const options = {
    method: "post",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(params),
  };
  return fetch(url, options).then((res) => res.json());
};

// create the helper with a custom fetcher
const graphiql = setupGraphiQL({ fetcher });

storiesOf("GraphQL Demo", module).add(
  "get user info",
  graphiql(`{
    user(id: "1") {
      name
    }
  }`)
);

Credits

While this addon was part of the Storybook monorepo, it received commits from the following authors:

Andrew Lisowski, Armand Abric, Brody McKee, Clément DUNGLER, Daniel Duan, Dependencies.io Bot, Filipp Riabchun, Gaëtan Maisse, Grey Baker, Hypnosphi, ImgBotApp, James Hush, Jimmy Somsanith, Lynn Chyi, Michael Shilman, Michaël De Boey, Norbert de Langen, Paul Rosania, Pavan Kumar Sunkara, Rajat Rao, Renovate Bot, Roman, Varun Vachhar, igor-dv, lonyele,

addon-graphql's People

Contributors

jonniebigodes avatar ndelangen avatar shilman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

addon-graphql's Issues

[Bug] storiesOf is now discontinued, but the setup guide shows an example using it

Describe the bug

The docs on how to use this addon seem to be stale. There's usage of a storybook function that is deprecated

Expected behavior

The readme and other docs should be inline with the main storybook framework

Environment

n/a

Additional context

Deprecation notice:
https://storybook.js.org/docs/react/migration-guide#storiesof-support-discontinued-by-default

Stale documentation:
https://storybook.js.org/addons/@storybook/addon-graphql
https://github.com/storybookjs/addon-graphql#readme

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.