Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@magidoc/plugin-reverse-schema-mapper

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@magidoc/plugin-reverse-schema-mapper - npm Package Compare versions

Comparing version 2.4.2 to 2.5.0

build/createReverseMapping.d.ts

4

build/index.js

@@ -1,2 +0,4 @@

export { ReverseGraphQLSchemaMapping } from './reverseMapping.js';
export { ReferenceKind } from './reverseUsage.js';
export { createReverseMapping } from './createReverseMapping.js';
//# sourceMappingURL=index.js.map

@@ -1,5 +0,7 @@

import { ReverseUsage } from './reverseUsage';
import { GraphQLNamedType } from 'graphql';
import { TypeReverseMapping } from './reverseUsage';
export declare class ReverseGraphQLSchemaMapping {
private mapping;
constructor(mapping: Map<string, ReverseUsage>);
constructor(mapping: Map<string, TypeReverseMapping>);
getFor(type: GraphQLNamedType): TypeReverseMapping | undefined;
}

@@ -1,12 +0,60 @@

import { GraphQLNamedType } from 'graphql';
export declare type ReverseUsage = {
referencedBy: ReadonlyArray<GraphQLNamedType>;
import { GraphQLArgument, GraphQLField, GraphQLObjectType, GraphQLUnionType } from 'graphql';
export declare type TypeReverseMapping = {
/**
* A list of references to this type.
*/
readonly references: Reference[];
};
export declare type ReverseInterfaceUsage = ReverseUsage & {
implementations: ReadonlyArray<GraphQLNamedType>;
export declare type Reference = UnionReference | ArgumentReference | FieldReference;
export declare enum ReferenceKind {
/**
* When type is referenced in a union object.
*/
UNION = "union",
/**
* When type is referenced as an argument for a field.
*/
ARGUMENT = "argument",
/**
* When type is referenced as a field.
*/
FIELD = "field"
}
export declare type UnionReference = {
/**
* The kind of reference.
*/
kind: ReferenceKind.UNION;
/**
* The union type that references this type.
*/
by: GraphQLUnionType;
};
export declare type ReverseScalarUsage = ReverseUsage;
export declare type ReverseUnionUsage = ReverseUsage;
export declare type ReverseObjectUsage = ReverseUsage;
export declare type ReverseInputObjectUsage = ReverseUsage;
export declare type ReverseEnumObjectUsage = ReverseUsage;
export declare type ArgumentReference = {
/**
* The kind of reference.
*/
kind: ReferenceKind.ARGUMENT;
/**
* The parent field that uses this argument.
*/
parent: GraphQLField<unknown, unknown, unknown>;
/**
* The argument that references this type.
*/
by: GraphQLArgument;
};
export declare type FieldReference = {
/**
* The kind of reference.
*/
kind: ReferenceKind.FIELD;
/**
* The parent object that uses this field.
*/
parent: GraphQLObjectType<unknown, unknown>;
/**
* The field that uses the type.
*/
by: GraphQLField<unknown, unknown, unknown>;
};

@@ -5,3 +5,3 @@ {

"private": false,
"version": "2.4.2",
"version": "2.5.0",
"type": "module",

@@ -27,5 +27,5 @@ "license": "MIT",

"devDependencies": {
"@types/jest": "^28.1.3",
"@types/node": "^18.0.0",
"jest": "^28.1.1",
"@types/jest": "^28.1.4",
"@types/node": "^18.0.1",
"jest": "^28.1.2",
"jest-extended": "^2.0.0",

@@ -32,0 +32,0 @@ "rollup": "^2.75.7",

> This plugin is still under development and is not ready for production yet.
# Magidoc - Fetch GraphQL Schema
# Magidoc - Reverse-Schema-Mapper
A library to perform reverse mapping of a GraphQL Schema, allowing to find where types are used or referenced.

@@ -5,0 +5,0 @@

@@ -1,9 +0,14 @@

import { ReverseUsage } from './reverseUsage'
import { GraphQLNamedType } from 'graphql'
import { TypeReverseMapping } from './reverseUsage'
export class ReverseGraphQLSchemaMapping {
private mapping: Map<string, ReverseUsage>
private mapping: Map<string, TypeReverseMapping>
constructor(mapping: Map<string, ReverseUsage>) {
constructor(mapping: Map<string, TypeReverseMapping>) {
this.mapping = mapping
}
getFor(type: GraphQLNamedType): TypeReverseMapping | undefined {
return this.mapping.get(type.name)
}
}

@@ -1,19 +0,71 @@

import { GraphQLNamedType } from 'graphql'
import {
GraphQLArgument,
GraphQLField,
GraphQLObjectType,
GraphQLUnionType,
} from 'graphql'
export type ReverseUsage = {
referencedBy: ReadonlyArray<GraphQLNamedType>
export type TypeReverseMapping = {
/**
* A list of references to this type.
*/
readonly references: Reference[]
}
export type ReverseInterfaceUsage = ReverseUsage & {
implementations: ReadonlyArray<GraphQLNamedType>
export type Reference = UnionReference | ArgumentReference | FieldReference
export enum ReferenceKind {
/**
* When type is referenced in a union object.
*/
UNION = 'union',
/**
* When type is referenced as an argument for a field.
*/
ARGUMENT = 'argument',
/**
* When type is referenced as a field.
*/
FIELD = 'field',
}
export type ReverseScalarUsage = ReverseUsage
export type UnionReference = {
/**
* The kind of reference.
*/
kind: ReferenceKind.UNION
/**
* The union type that references this type.
*/
by: GraphQLUnionType
}
export type ReverseUnionUsage = ReverseUsage
export type ArgumentReference = {
/**
* The kind of reference.
*/
kind: ReferenceKind.ARGUMENT
/**
* The parent field that uses this argument.
*/
parent: GraphQLField<unknown, unknown, unknown>
/**
* The argument that references this type.
*/
by: GraphQLArgument
}
export type ReverseObjectUsage = ReverseUsage
export type ReverseInputObjectUsage = ReverseUsage
export type ReverseEnumObjectUsage = ReverseUsage
export type FieldReference = {
/**
* The kind of reference.
*/
kind: ReferenceKind.FIELD
/**
* The parent object that uses this field.
*/
parent: GraphQLObjectType<unknown, unknown>
/**
* The field that uses the type.
*/
by: GraphQLField<unknown, unknown, unknown>
}

@@ -1,5 +0,71 @@

describe('given a context', () => {
it('passes', () => {
expect(true).toBe(true)
import { GraphQLNamedType, GraphQLObjectType } from 'graphql'
import { createReverseMapping } from '../src'
import { ReferenceKind } from '../src/reverseUsage'
const schema = getTestSchema()
const reverse = createReverseMapping(schema)
describe('given schema', () => {
it('should create a reverse mapping for default types', () => {
expect(reverse.getFor(getMandatoryType('String'))?.references).toHaveLength(
33,
)
expect(
reverse.getFor(getMandatoryType('Boolean'))?.references,
).toHaveLength(12)
})
it('should generate field references', () => {
const parentType = getMandatoryType('Test')
const result = reverse.getFor(getMandatoryType('Deferrable'))
const fieldResult = result?.references?.find(
(ref) => ref.kind === ReferenceKind.FIELD,
)
expect(fieldResult).toEqual({
kind: ReferenceKind.FIELD,
parent: parentType,
by: (parentType as GraphQLObjectType).getFields().deferrable,
})
})
it('should generate argument references', () => {
const targetField = getMandatoryField(
schema.getQueryType(),
'hasCustomScalarArg',
)
const result = reverse.getFor(getMandatoryType('SomeCustomScalar'))
const argResult = result?.references.find(
(ref) => ref.kind === ReferenceKind.ARGUMENT,
)
expect(argResult).toEqual({
kind: ReferenceKind.ARGUMENT,
by: targetField.args.find((arg) => arg.name === 'nonStandardScalar'),
parent: targetField,
})
})
it('should generate union references', () => {
const first = getMandatoryType('First')
const result = reverse.getFor(first)
const unionResult = result?.references.find(
(ref) => ref.kind === ReferenceKind.UNION,
)
expect(unionResult).toEqual({
kind: ReferenceKind.UNION,
by: getMandatoryType('TestUnion'),
})
})
})
function getMandatoryType(name: string): GraphQLNamedType {
const result = schema.getType(name)
if (!result) {
fail(
`expected type '${name}' to exist but did not... did you modify the test schema?`,
)
}
return result
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc