Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Storybook addon to display the GraphiQL IDE

License

NotificationsYou must be signed in to change notification settings

storybookjs/addon-graphql

Repository files navigation

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

Framework Support

Screenshot

Getting Started

First, install the addon

yarn add @storybook/addon-graphql --dev

Import thesetupGraphiQL 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 laterconstgraphiql=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

ThesetupGraphiQL 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 thefetch 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";constfetcher=(params)=>{constoptions={method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(params),};returnfetch(url,options).then((res)=>res.json());};// create the helper with a custom fetcherconstgraphiql=setupGraphiQL({ fetcher});storiesOf("GraphQL Demo",module).add("get user info",graphiql(`{    user(id: "1") {      name    }  }`));

Credits

While this addon was part of theStorybook 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,

About

Storybook addon to display the GraphiQL IDE

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp