Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andimarek/graphql-analyzer
Static analysis of GraphQL queries
https://github.com/andimarek/graphql-analyzer
graphql
Last synced: 20 days ago
JSON representation
Static analysis of GraphQL queries
- Host: GitHub
- URL: https://github.com/andimarek/graphql-analyzer
- Owner: andimarek
- License: mit
- Created: 2019-07-07T08:13:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T03:55:07.000Z (almost 2 years ago)
- Last Synced: 2024-10-13T14:16:31.054Z (about 1 month ago)
- Topics: graphql
- Language: TypeScript
- Homepage:
- Size: 575 KB
- Stars: 15
- Watchers: 2
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GraphQL analyzer
Static analysis of GraphQL queries (analysis without actually executing the query).
Please see this blog post for background and details: [Static analysis of GraphQL queries
](https://www.graphql.de/blog/static-query-analysis/)# Usage
Add to your project:
```sh
npm install graphql-analyzer
````graphql-analyzer` exports three functions:
```typescript
import {analyzeQuery, printDependencyGraph, traverseFieldVertices } from 'graphql-analyzer';
````analyseQuery` returns a the root `FieldVertex` of the dependency graph.
Details:
```typescript
export interface FieldVertex {
id: string;
fields: Array;
objectType: GraphQLObjectType;
fieldDefinition: GraphQLField;
dependsOn: Array;
dependOnMe: Array;
}
export function analyzeQuery(
document: DocumentNode,
schema: GraphQLSchema,
rawVariableValues?: { [key: string]: any; },
validateQuery?: boolean)
: FieldVertex;
````printDependencyGraph` returns all vertices and all edges for a dependency graph:
```typescript
export interface DependencyEdge {
from: FieldVertex;
to: FieldVertex;
conditional: boolean;
}
export function printDependencyGraph(
root: FieldVertex)
: [Array, Array];
````traverseFieldVertices` lets you traverse the graph returned by `analyzeQuery`:
```typescript
export function traverseFieldVertices(
root: FieldVertex,
visitor: (vertex: FieldVertex) => void)
: void;
```