Giter Site home page Giter Site logo

vvvi / graphql-string Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 48 KB

A simple module for avoiding duplicated fragments in graphql when is used as string.

Home Page: https://www.npmjs.com/package/graphql-string

License: MIT License

TypeScript 100.00%

graphql-string's Introduction

graphql-string

Description

graphql-string is an essential npm module designed to simplify the process of avoiding duplicated fragments in GraphQL when used as strings. With its intuitive functionality, graphql-string empowers developers to eliminate redundant code fragments efficiently, ensuring clean and optimized GraphQL queries.

Installation

$ npm i graphql-string 

Usage

Use template literal 'gqls' as below:

import gqls from 'graphql-string';

const comparisonFields = gqls`
  fragment comparisonFields on Character {
    name
    appearsIn
    friends {
      name
    }
  }`;

const query = gqls`{
  ${comparisonFields}
  ${comparisonFields}
  leftComparison: hero(episode: EMPIRE) {
    ...comparisonFields
  }
  rightComparison: hero(episode: JEDI) {
    ...comparisonFields
  }
}`;

Use cases

Could be used for pretty simple graphql queries and fragments as strings. Is good to use within NextJS Fetch function.

For complex queries is recommended to use graphql-tag package, like:

import gql from 'graphql-tag';
import { print } from 'graphql/language/printer';

const ast = gql`
  ${someFragment}
  {
    data() {
      ...Data
    }
  }
`
const query = print(ast);

graphql-string's People

Stargazers

 avatar

Watchers

 avatar

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.