Skip to content

Commit 5067c28

Browse files
committed
✨ GraphQL Tree as a separate package
Initial commit of separation from zeus
0 parents  commit 5067c28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+6217
-0
lines changed

Diff for: .editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
insert_final_newline = false
15+
trim_trailing_whitespace = false

Diff for: .eslintrc.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
3+
extends: [
4+
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
5+
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
6+
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
7+
],
8+
parserOptions: {
9+
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
10+
sourceType: 'module', // Allows for the use of imports
11+
},
12+
plugins: ['@typescript-eslint', 'prettier'],
13+
rules: {
14+
'@typescript-eslint/no-use-before-define': 0,
15+
'@typescript-eslint/explicit-function-return-type': 0,
16+
'@typescript-eslint/no-var-requires': 0,
17+
'@typescript-eslint/explicit-module-boundary-types': 0,
18+
},
19+
};

Diff for: .github/workflows/release.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
# Setup .npmrc file to publish to npm
11+
- uses: actions/setup-node@v1
12+
with:
13+
node-version: '14.x'
14+
registry-url: 'https://registry.npmjs.org'
15+
- run: npm install
16+
- run: npm test
17+
- run: npm run build
18+
- run: npm publish --access public --tag latest
19+
env:
20+
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

Diff for: .gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.vscode
2+
.DS_STORE
3+
node_modules
4+
.module-cache
5+
*.log*
6+
build
7+
dist
8+
docs-dist
9+
lib
10+
.idea
11+
.docz
12+
.tscache
13+
package-lock.json
14+
*.tsbuildinfo*

Diff for: .npmignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.vscode
2+
.DS_STORE
3+
.docz
4+
.tscache
5+
node_modules
6+
.module-cache
7+
*.log*
8+
build
9+
dist
10+
src
11+
example
12+
images
13+
.idea
14+
package-lock.json
15+
__tests__

Diff for: .prettierrc.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
arrowParens: "always",
3+
printWidth: 80,
4+
semi: true,
5+
trailingComma: "all",
6+
singleQuote: true,
7+
printWidth: 120,
8+
tabWidth: 2
9+
};

Diff for: CONTRIBUTING.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Contributing to GraphQL JS Tree
2+
3+
We welcome contributions to GraphQL Tree of any kind including documentation, themes,
4+
organization, tutorials, blog posts, bug reports, issues, feature requests,
5+
feature implementations, pull requests, answering questions on the forum,
6+
helping to manage issues, etc.
7+
8+
_Changes to the codebase **and** related documentation, e.g. for a new feature, should still use a single pull request._
9+
10+
## Table of Contents
11+
12+
- [Contributing to GraphQL JS Tree](#contributing-to-graphql-js-tree)
13+
- [Table of Contents](#table-of-contents)
14+
- [Reporting Issues](#reporting-issues)
15+
- [Code Contribution](#code-contribution)
16+
17+
18+
## Reporting Issues
19+
20+
If you believe you have found a defect in GraphQL Zeus or its documentation, use
21+
the GitHub [issue tracker](https://github.com/graphql-editor/graphql-zeus/issues) to report
22+
the problem to the maintainers.
23+
24+
## Code Contribution
25+
26+
GraphQL Zeus is still looking for its direction so remember functionality has to:
27+
28+
- repair existing bugs
29+
- introduce new feature requests
30+
31+
**Bug fixes are, of course, always welcome.**

Diff for: LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Artur Czemiel
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
![](images/zeus.gif)
2+
3+
[![npm](https://img.shields.io/npm/v/graphql-js-tree.svg?style=flat-square)](https://www.npmjs.com/package/graphql-js-tree) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](http://commitizen.github.io/cz-cli/) [![npm downloads](https://img.shields.io/npm/dt/graphql-js-tree.svg?style=flat-square)](https://www.npmjs.com/package/graphql-js-tree)
4+
5+
Simplier approach to GraphQL parsing. Using graphql-js library and parsing AST to simplier types. It is a backbone of `graphql-zeus` and `graphql-editor`
6+
7+
## How it works
8+
9+
It creates very simple `ParserTree` from GraphQL schema
10+
11+
```js
12+
import { Parser, TreeToGraphQL } from 'graphql-js-tree';
13+
14+
const schemaFileContents = `
15+
type Query{
16+
hello: String!
17+
}
18+
schema{
19+
query: Query
20+
}
21+
`;
22+
23+
const parsedSchema = Parser.parse(schemaFileContents);
24+
25+
// Backwards
26+
27+
const graphqlString = TreeToGraphQL.parse(parsedSchema);
28+
```
29+
30+
## Table of contents
31+
32+
- [How it works](#how-it-works)
33+
- [Table of contents](#table-of-contents)
34+
- [License](#license)
35+
- [Support](#support)
36+
- [Contribute](#contribute)
37+
38+
## License
39+
40+
MIT
41+
42+
## Support
43+
44+
[Join our GraphQL Editor Channel](https://join.slack.com/t/graphqleditor/shared_invite/enQtNDkwOTgyOTM5OTc1LWI4YjU3N2U5NGVkNzQ2NzY5MGUxMTJiNjFlZDM1Zjc2OWRmNTI0NDM3OWUxYTk4Yjk3MzZlY2QwOWUzZmM2NDI)
45+
46+
Leave a star ;)
47+
48+
## Contribute
49+
50+
For a complete guide to contributing to GraphQL Editor, see the [Contribution Guide](CONTRIBUTING.md).
51+
52+
1. Fork this repo
53+
2. Create your feature branch: git checkout -b feature-name
54+
3. Commit your changes: git commit -am 'Add some feature'
55+
4. Push to the branch: git push origin my-new-feature
56+
5. Submit a pull request

Diff for: commitlint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { extends: ['@commitlint/config-conventional'] };

Diff for: jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
moduleFileExtensions: ['ts', 'tsx', 'js'],
4+
moduleNameMapper: {
5+
'@/(.*)': ['<rootDir>/src/$1'],
6+
},
7+
testMatch: ['**/__tests__/**/*.spec.(ts|tsx)'],
8+
watchPathIgnorePatterns: ['node_modules'],
9+
watchman: false,
10+
};

Diff for: package.json

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "graphql-js-tree",
3+
"version": "0.0.1",
4+
"private": false,
5+
"license": "MIT",
6+
"description": "GraphQL Parser providing simplier structure",
7+
"homepage": "https://graphqleditor.com",
8+
"main": "lib/index.js",
9+
"types": "lib/index.d.ts",
10+
"scripts": {
11+
"build": "ttsc --build tsconfig.build.json",
12+
"start": "ttsc --build tsconfig.build.json --watch",
13+
"test": "jest",
14+
"lint": "ttsc && eslint \"./src/**/*.{ts,js}\" --quiet --fix"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/graphql-editor/graphql-js-tree.git"
19+
},
20+
"bugs": {
21+
"url": "https://github.com/graphql-editor/graphql-js-tree.git"
22+
},
23+
"devDependencies": {
24+
"@commitlint/cli": "^8.3.5",
25+
"@commitlint/config-conventional": "^8.3.4",
26+
"@types/graphql": "^14.5.0",
27+
"@types/jest": "^25.1.4",
28+
"@types/node": "^13.9.0",
29+
"@typescript-eslint/eslint-plugin": "^4.15.0",
30+
"@typescript-eslint/parser": "^4.15.0",
31+
"cz-conventional-changelog": "^3.1.0",
32+
"eslint": "^7.19.0",
33+
"eslint-config-prettier": "^7.2.0",
34+
"eslint-plugin-prettier": "^3.3.1",
35+
"husky": "^4.2.3",
36+
"jest": "^25.2.4",
37+
"prettier": "^2.0.2",
38+
"ts-jest": "^26.5.1",
39+
"ts-node": "^9.0.0",
40+
"ttypescript": "^1.5.12",
41+
"typescript": "^4.1.2",
42+
"typescript-transform-paths": "^2.0.0"
43+
},
44+
"dependencies": {
45+
"graphql": "^15.4.0"
46+
},
47+
"config": {
48+
"commitizen": {
49+
"path": "./node_modules/cz-conventional-changelog"
50+
}
51+
},
52+
"husky": {
53+
"hooks": {
54+
"pre-commit": "npm run lint"
55+
}
56+
}
57+
}

Diff for: src/Models/DisplayMap.ts

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { TypeDefinition, TypeExtension, TypeSystemDefinition } from './Spec';
2+
3+
export enum TypeDefinitionDisplayStrings {
4+
type = 'type',
5+
enum = 'enum',
6+
interface = 'interface',
7+
input = 'input',
8+
scalar = 'scalar',
9+
union = 'union',
10+
directive = 'directive',
11+
}
12+
export enum TypeSystemDefinitionDisplayStrings {
13+
directive = 'directive',
14+
schema = 'schema',
15+
definition = 'definition',
16+
field = 'field',
17+
member = 'member',
18+
}
19+
20+
export const TypeDefinitionDisplayMap: Record<
21+
TypeDefinition | TypeExtension | TypeSystemDefinition.DirectiveDefinition,
22+
TypeDefinitionDisplayStrings
23+
> = {
24+
[TypeDefinition.ObjectTypeDefinition]: TypeDefinitionDisplayStrings.type,
25+
[TypeDefinition.EnumTypeDefinition]: TypeDefinitionDisplayStrings.enum,
26+
[TypeDefinition.InterfaceTypeDefinition]: TypeDefinitionDisplayStrings.interface,
27+
[TypeDefinition.InputObjectTypeDefinition]: TypeDefinitionDisplayStrings.input,
28+
[TypeDefinition.ScalarTypeDefinition]: TypeDefinitionDisplayStrings.scalar,
29+
[TypeDefinition.UnionTypeDefinition]: TypeDefinitionDisplayStrings.union,
30+
[TypeExtension.ObjectTypeExtension]: TypeDefinitionDisplayStrings.type,
31+
[TypeExtension.EnumTypeExtension]: TypeDefinitionDisplayStrings.enum,
32+
[TypeExtension.InterfaceTypeExtension]: TypeDefinitionDisplayStrings.interface,
33+
[TypeExtension.InputObjectTypeExtension]: TypeDefinitionDisplayStrings.input,
34+
[TypeExtension.ScalarTypeExtension]: TypeDefinitionDisplayStrings.scalar,
35+
[TypeExtension.UnionTypeExtension]: TypeDefinitionDisplayStrings.union,
36+
[TypeSystemDefinition.DirectiveDefinition]: TypeDefinitionDisplayStrings.directive,
37+
};
38+
39+
export const TypeSystemDefinitionDisplayMap: Record<TypeSystemDefinition, TypeSystemDefinitionDisplayStrings> = {
40+
[TypeSystemDefinition.DirectiveDefinition]: TypeSystemDefinitionDisplayStrings.directive,
41+
[TypeSystemDefinition.FieldDefinition]: TypeSystemDefinitionDisplayStrings.field,
42+
[TypeSystemDefinition.SchemaDefinition]: TypeSystemDefinitionDisplayStrings.schema,
43+
[TypeSystemDefinition.TypeDefinition]: TypeSystemDefinitionDisplayStrings.definition,
44+
[TypeSystemDefinition.UnionMemberDefinition]: TypeSystemDefinitionDisplayStrings.member,
45+
};

Diff for: src/Models/Options.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum Options {
2+
array = 'array',
3+
required = 'required',
4+
arrayRequired = 'arrayRequired',
5+
}

Diff for: src/Models/ParserTree.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Options } from './Options';
2+
import { Directive, OperationType } from './Spec';
3+
import { GraphQLNodeParams } from './Types';
4+
5+
export interface ParserField {
6+
name: string;
7+
type: {
8+
name: string;
9+
options?: Options[];
10+
operations?: OperationType[];
11+
directiveOptions?: Directive[];
12+
};
13+
data: GraphQLNodeParams;
14+
args?: ParserField[];
15+
interfaces?: string[];
16+
directives?: ParserField[];
17+
description?: string;
18+
}
19+
20+
export interface ParserTree {
21+
nodes: ParserField[];
22+
}

0 commit comments

Comments
 (0)