How to use graphiql - 10 common examples

To help you get started, we’ve selected a few graphiql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graphql / graphiql / examples / graphiql-webpack / src / index.jsx View on Github external
import React from 'react';
import { render } from 'react-dom';
import GraphiQL from 'graphiql';
import 'graphiql/graphiql.css';

const Logo = () =&gt; <span>My Corp</span>;

// See GraphiQL Readme - Advanced Usage section for more examples like this
GraphiQL.Logo = Logo;

const App = () =&gt; (
   {
      const data = await fetch(
        'https://swapi-graphql.netlify.com/.netlify/functions/index',
        {
          method: 'POST',
          headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
          },
          body: JSON.stringify(graphQLParams),
          credentials: 'include',
        },
github prisma-labs / graphql-playground / packages / graphql-playground-react / src / components / Playground / GraphQLEditor.tsx View on Github external
componentDidMount() {
    // Ensure a form of a schema exists (including `null`) and
    // if not, fetch one using an introspection query.
    // this.props.fetchSchema()

    // Utility for keeping CodeMirror correctly sized.
    this.codeMirrorSizer = new CodeMirrorSizer()
    ;(global as any).g = this
  }
github prisma-labs / graphql-playground / packages / graphql-playground-react / src / components / Playground / GraphQLEditor.tsx View on Github external
autoCompleteLeafs() {
    const { insertions, result } = fillLeafs(
      this.props.schema,
      this.props.query,
    ) as {
      insertions: Array&lt;{ index: number; string: string }&gt;
      result: string
    }
    if (insertions &amp;&amp; insertions.length &gt; 0) {
      const editor = this.queryEditorComponent.getCodeMirror()
      editor.operation(() =&gt; {
        const cursor = editor.getCursor()
        const cursorIndex = editor.indexFromPos(cursor)
        editor.setValue(result)
        let added = 0
        try {
          /* tslint:disable-next-line */
          const markers = insertions.map(({ index, string }) =&gt;
github kadirahq / graphql-blog-schema / src / App.js View on Github external
import React, { Component } from 'react';
import GraphiQL from 'graphiql';
import fetch from 'isomorphic-fetch';
import Schema from './schema.js';
import { graphql } from 'graphql';

GraphiQL.Logo = class Logo extends Component {
  render() {
    let style = {
      fontWeight: 800,
      fontSize: 16,
      color: '#252525'
    };

    return (
      <span style="{style}">Learn GraphQL Sandbox</span>
    );
  }
}

export default class App extends Component {
  fetchData({query, variables}) {
    let queryVariables = {};
github shahankit / custom-graphiql / src / components / CustomGraphiQL.js View on Github external
    const logo = children.find(child => child.type === GraphiQL.Logo);
    const footer = children.find(child => child.type === GraphiQL.Footer);
github mattkrick / cashay-playground / src / App.js View on Github external
import React, { Component } from 'react';
import GraphiQL from 'graphiql';
import fetch from 'isomorphic-fetch';
import gqlSchema from './schema.js';
import { graphql } from 'graphql';


GraphiQL.Logo = class Logo extends Component {
  render() {
    let style = {
      fontWeight: 800,
      fontSize: 16,
      color: "#252525"
    };

    return (
      <span style="{style}">Learn GraphQL Sandbox</span>
    );
  }
}

export default class App extends Component {
  fetchData({query, variables}) {
    let queryVariables = {};
github prisma-labs / graphql-playground / packages / graphql-playground-react / src / components / Playground / ExplorerTabs / SideTabs.tsx View on Github external
let onMouseMove: any = moveEvent =&gt; {
      if (moveEvent.buttons === 0) {
        return onMouseUp()
      }

      const app = this.ref
      const cursorPos = moveEvent.clientX - getLeft(app) - offset
      const newSize = app.clientWidth - cursorPos
      const maxSize = window.innerWidth - 50
      const docsSize = maxSize &lt; newSize ? maxSize : newSize

      if (docsSize &lt; 100) {
        this.props.setDocsVisible(
          this.props.sessionId,
          false,
          this.props.docs.activeTabIdx,
        )
      } else {
        this.props.setDocsVisible(
          this.props.sessionId,
          true,
          this.props.docs.activeTabIdx,
        )
github prisma-labs / graphql-playground / packages / graphql-playground-react / src / components / Playground / ExplorerTabs / SideTabs.tsx View on Github external
private handleDocsResizeStart = downEvent =&gt; {
    downEvent.preventDefault()

    const hadWidth = this.props.docs.docsWidth
    const offset = downEvent.clientX - getLeft(downEvent.target)

    let onMouseMove: any = moveEvent =&gt; {
      if (moveEvent.buttons === 0) {
        return onMouseUp()
      }

      const app = this.ref
      const cursorPos = moveEvent.clientX - getLeft(app) - offset
      const newSize = app.clientWidth - cursorPos
      const maxSize = window.innerWidth - 50
      const docsSize = maxSize &lt; newSize ? maxSize : newSize

      if (docsSize &lt; 100) {
        this.props.setDocsVisible(
          this.props.sessionId,
          false,
github prisma-labs / graphql-playground / packages / graphql-playground-react / src / components / Playground / GraphQLEditor.tsx View on Github external
let onMouseMove: any = moveEvent => {
      if (moveEvent.buttons === 0) {
        return onMouseUp()
      }

      const editorBar = ReactDOM.findDOMNode(this.editorBarComponent)
      const leftSize = moveEvent.clientX - getLeft(editorBar) - offset
      const rightSize = editorBar.clientWidth - leftSize
      this.props.setEditorFlex(leftSize / rightSize)
    }
github prisma-labs / graphql-playground / packages / graphql-playground-react / src / components / Playground / GraphQLEditor.tsx View on Github external
private handleResizeStart = downEvent => {
    if (!this.didClickDragBar(downEvent)) {
      return
    }

    downEvent.preventDefault()

    const offset = downEvent.clientX - getLeft(downEvent.target)

    let onMouseMove: any = moveEvent => {
      if (moveEvent.buttons === 0) {
        return onMouseUp()
      }

      const editorBar = ReactDOM.findDOMNode(this.editorBarComponent)
      const leftSize = moveEvent.clientX - getLeft(editorBar) - offset
      const rightSize = editorBar.clientWidth - leftSize
      this.props.setEditorFlex(leftSize / rightSize)
    }

    let onMouseUp: any = () => {
      document.removeEventListener('mousemove', onMouseMove)
      document.removeEventListener('mouseup', onMouseUp)
      onMouseMove = null