Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@khanacademy/graphql-flow

Package Overview
Dependencies
Maintainers
0
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@khanacademy/graphql-flow

This is a tool for generating flow types from graphql queries in javascript frontends.

  • 3.1.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
244
decreased by-17.57%
Maintainers
0
Weekly downloads
 
Created
Source

Graphql Flow Generation

This is a tool for generating flow types from graphql queries in javascript frontends.

Using as a CLI tool

Write a config file, following the schema defined in src/cli/schema.json, either as a .json file, or a .js file that module.exports an object adhering to the schema.

Then run from the CLI, like so:

$ graphql-flow path/to/config.json

Files will be discovered relative to the crawl.root.

Multiple generate configs

To customize type generation for certain directories or files, you can provide multiple generate configs as an array, using match and exclude to customize behavior.

For a given file containing operations, the first generate config that matches that path (and doesn't exclude it) will be used to generate types for those operations. If a generate config doesn't have a match attribute, it will match all files (but might exclude some via the exclude attribute).

For example:

// dev/graphql-flow/config.js

const options = {
    schemaFilePath: "../../gengraphql/composed-schema.graphql",
    regenerateCommand: "make gqlflow",
    generatedDirectory: "__graphql-types__",
    exclude: [
        /_test.js$/,
        /.fixture.js$/,
        /\b__flowtests__\b/,
    ],
};

module.exports = {
    crawl: {
        root: "../../",
    },
    generate: [
        {
            ...options,
            schemaFilePath: "../../gengraphql/course-editor-schema.graphql",
            match: [/\bcourse-editor-package\b/, /\bcourse-editor\b/],
        },
        {
            ...options,
            match: [/\bdiscussion-package\b/]
            experimentalEnums: true,
        },
        options,
    ],
};

Introspecting your backend's graphql schema

Here's how to get your backend's schema in the way that this tool expects, using the builtin 'graphql introspection query':

import {getIntrospectionQuery} from 'graphql';
import fs from 'fs';
import fetch from 'node-fetch';

const query = getIntrospectionQuery({descriptions: true}),

const response = await fetch(`https://my-backend.com`, {
    method: 'POST',
    body: query,
    headers: {
        // You definitely shouldn't be allowing arbitrary queries without
        // some strict access control.
        'X-header-that-allows-arbitrary-queries': 'my-secret-key',
    },
    contentType: 'application/json',
});
const fullResponse = await response.json();
fs.writeFileSync('./server-introspection-response.json', JSON.stringify(fullResponse.data, null, 2));

FAQs

Package last updated on 30 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc