Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/3axap4ehko/graphql-retag
https://github.com/3axap4ehko/graphql-retag
fragment fragments graphql graphql-tag reusable
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/3axap4ehko/graphql-retag
- Owner: 3axap4eHko
- Created: 2019-01-28T21:54:24.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-09-26T16:57:20.000Z (about 3 years ago)
- Last Synced: 2024-09-15T03:31:53.045Z (2 months ago)
- Topics: fragment, fragments, graphql, graphql-tag, reusable
- Language: TypeScript
- Homepage:
- Size: 165 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GraphQL reTag
Helpful utility that wraps `graphql-tag` module for parsing GraphQL queries, supports nesting fragments and resolves fragments dependencies.
[![NPM version][npm-image]][npm-url]
[![Downloads][downloads-image]][npm-url]
[![Build Status][travis-image]][travis-url]## Usage
Let's assume we have a fragment `image`
`./fragments/image.js`
```js
import gql from 'graphql-retag';export default gql`
fragment image on Image {
large
inline
}
`;
```
Fragment `image` used by fragment `userInfo`
`./fragments/userInfo.js`
```js
import gql from 'graphql-retag';
import image from './image';export default gql`
fragment userInfo on User {
username
avatar {
...${image}
}
}
`;
```And both used by query `GetAllPosts`
`./GetAllPosts.js`
```
import gql from 'graphql-retag';
import image from './fragments/image';
import userInfo from './fragments/userInfo';export default gql`
query GetAllPosts(first: 100) {
id
title
author {
...${userInfo}
}
content
images {
...${images}
}
comments {
content
author {
...${userInfo}
}
}
}
`;```
`graphql-retag` resolves even nested fragment dependencies without conflicts.
## License
[The MIT License](http://opensource.org/licenses/MIT)
Copyright (c) 2020 Ivan Zakharchanka[downloads-image]: https://img.shields.io/npm/dm/graphql-retag.svg
[npm-url]: https://www.npmjs.com/package/graphql-retag
[npm-image]: https://img.shields.io/npm/v/graphql-retag.svg[travis-url]: https://travis-ci.org/3axap4eHko/graphql-retag
[travis-image]: https://img.shields.io/travis/3axap4eHko/graphql-retag/master.svg