Socket
Book a DemoInstallSign in
Socket

gql-dedup

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gql-dedup

A graphql-tag improvement library which de-duplicates fragments.

1.0.3
latest
Source
npmnpm
Version published
Weekly downloads
3.1K
-5.69%
Maintainers
1
Weekly downloads
 
Created
Source

gql-dedup: a graphql-tag improvement library which de-duplicates fragments

Well-known Apollo's graphql-tag library hasn't been updated for a long time, and there has been several PRs got stuck there.

The current library solves one common weakness of graphql-tag: it allows to refer fragments multiple times and have them de-duplicated in the query.

Example

Imagine we have a common FragDate fragment which two other fragments, FragCreated and FragUpdated, depend on. Then, with the default graphql-tag library, using of both FragCreated and FragUpdated in the same query won't be possible since FragDate would be included twice, and we'd get a server-side error.

Here comes graphql-tag: it de-duplicates fragments each time they're used.

import gql from "gql-dedup";

const FragDate = gql`
  fragment FragDate on User {
    day
    month
    year
  }
`;

const FragCreated = gql`
  fragment FragCreated on User {
    created {
      ...FragDate
    }
  }
  ${FragDate}
`;

const FragUpdated = gql`
  fragment FragUpdated on User {
    updated {
      ...FragDate
    }
  }
  ${FragDate}
`;

const Query = gql`
  query User {
    viewer {
      ...FragCreated
      ...FragUpdated
    }
  }
  ${FragCreated}
  ${FragUpdated}
`;

Result (notice that FragDate is included only once):

query User {
  viewer {
    ...FragCreated
    ...FragUpdated
  }
}
fragment FragCreated on User {
  created {
    ...FragDate
  }
}
fragment FragDate on User {
  day
  month
  year
}
fragment FragUpdated on User {
  updated {
    ...FragDate
  }
}

Keywords

graphql

FAQs

Package last updated on 11 Oct 2023

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.