graphql-retag
v0.1.17
Published
Helpful utility that wraps `graphql-tag` module for parsing GraphQL queries, supports nesting fragments and resolves dependencies.
Downloads
7
Readme
GraphQL reTag
Helpful utility that wraps graphql-tag
module for parsing GraphQL queries, supports nesting fragments and resolves fragments dependencies.
Usage
Let's assume we have a fragment image
./fragments/image.js
import gql from 'graphql-retag';
export default gql`
fragment image on Image {
large
inline
}
`;
Fragment image
used by fragment userInfo
./fragments/userInfo.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 Copyright (c) 2020 Ivan Zakharchanka