Skip to content

Rewrite in TypeScript #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
eea6332
working on adding some typedefs
tlivings Mar 2, 2022
e20e1bf
more to do
tlivings Mar 23, 2022
fd6f150
merged
tlivings Mar 23, 2022
1f14cb4
initial tests passing
tlivings Nov 4, 2022
da12c62
Fixed context injection, datasources, and converted examples/composit…
tlivings Nov 15, 2024
1518635
Fixed examples, fixed dataSources in contrext.
tlivings Nov 15, 2024
8b450f2
added some documentation
tlivings Nov 18, 2024
4405656
Added more tests
tlivings Nov 19, 2024
3d8db33
fallback name for data sources is the class name
tlivings Nov 19, 2024
7dab075
latest build
tlivings Nov 19, 2024
3602b8f
added a resolve binding test
tlivings Nov 19, 2024
21c993e
added a memoize test
tlivings Nov 19, 2024
50ff5cd
added more test coverage
tlivings Nov 19, 2024
ca80be8
correct context being objected to data source
tlivings Nov 20, 2024
e646fbd
updates, readme
tlivings Nov 20, 2024
e4aabb2
updated dependencies
tlivings Nov 20, 2024
28f83f2
changelog
tlivings Nov 20, 2024
cca6297
added type to context
tlivings Nov 20, 2024
d413010
fixed examples again
tlivings Nov 21, 2024
5bd591b
corrected dataSourceOverrides name
tlivings Nov 21, 2024
1d9217c
latest build
tlivings Nov 21, 2024
5426b3d
added mocks tests
tlivings Nov 21, 2024
2829731
Updated versioning to reflect the proper version planned
tlivings Jan 28, 2025
d017b5a
export GlobalContext, clean up typing for IResolvers
tlivings Jan 28, 2025
2cbb86a
Updated context to not only be extendable with a given type, but to b…
tlivings Jan 28, 2025
b9f3c7e
Merge branch 'master' into ts-conversion
tlivings Jan 28, 2025
c4611f5
Merge pull request #109 from tlivings/ts-conversion
tlivings Jan 28, 2025
415083e
Recent build
tlivings Jan 28, 2025
9827246
updated eslint
tlivings Jan 28, 2025
9373e04
More tests, fixed transforms.
tlivings Apr 16, 2025
a03b067
bumped version
tlivings Apr 16, 2025
2059c35
Able to mix together contexts from wrapping components... Maybe don't…
tlivings Apr 24, 2025
7e8d609
Update README
tlivings Apr 24, 2025
8c2fa1f
Fixed types for datasources.
tlivings Apr 25, 2025
c582e57
Next version
tlivings Apr 25, 2025
4e68e3b
Updated composition examples datasource types
tlivings Apr 25, 2025
fdfd53f
Updated documentation and removed unnecessary types and files.
tlivings Apr 25, 2025
8f92b7c
Updated federation and fixed linting
tlivings Apr 25, 2025
dae38e5
removed TODO.md
tlivings May 7, 2025
854bee4
removed trailing comma
tlivings May 7, 2025
47377e8
bumped version to next official release
tlivings May 7, 2025
6c1a772
latest build
tlivings May 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .eslintrc

This file was deleted.

11 changes: 0 additions & 11 deletions .nycrc

This file was deleted.

11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### v6.0.0

- Converted to TS
- BREAKING removed `delegateToComponent`
- BREAKING excludes removed as an option in import configuration. Transforms used instead as part of a `SubschemaConfig`.
- BREAKING upgraded to graphql 16.9+ peer

===

### v5.0.1

- Update @graphql-tools/utils dependency and fix samples for Apollo server v3.
Expand Down Expand Up @@ -179,4 +188,4 @@

- Fixed .npmignore to not include misc files that added to the package size

### v1.0.0 — promoted from alpha.23
### v1.0.0 — promoted from alpha.23
403 changes: 228 additions & 175 deletions README.md

Large diffs are not rendered by default.

118 changes: 118 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { GraphQLResolveInfo, GraphQLSchema } from 'graphql';
import { IResolvers, PruneSchemaOptions, TypeSource, SchemaMapper } from '@graphql-tools/utils';
import { IMocks } from '@graphql-tools/mock';
import { SubschemaConfig } from '@graphql-tools/delegate';
export type ResolverFunction = (_: any, args: any, ctx: any, info: GraphQLResolveInfo) => any;
export interface IGraphQLComponentConfigObject {
component: IGraphQLComponent;
configuration?: SubschemaConfig;
}
export interface ComponentContext extends Record<string, unknown> {
dataSources: DataSourceMap;
}
export type ContextFunction = ((context: Record<string, unknown>) => any);
export interface IDataSource {
name: string;
[key: string | symbol]: any;
}
/**
* Type for implementing data sources
* When defining a data source class, methods should accept context as their first parameter
* @example
* class MyDataSource {
* name = 'MyDataSource';
*
* // Context is required as first parameter when implementing
* getData(context: ComponentContext, id: string) {
* return { id };
* }
* }
*/
export type DataSourceDefinition<T> = {
[P in keyof T]: T[P] extends Function ? (context: ComponentContext, ...args: any[]) => any : T[P];
};
/**
* Type for consuming data sources in resolvers
* When using a data source method, the context is automatically injected
* @example
* // In a resolver:
* Query: {
* getData(_, { id }, context) {
* // Context is automatically injected, so you don't pass it
* return context.dataSources.MyDataSource.getData(id);
* }
* }
*/
export type DataSource<T> = {
[P in keyof T]: T[P] extends (context: ComponentContext, ...p: infer P) => infer R ? (...p: P) => R : T[P];
};
export type DataSourceMap = {
[key: string]: IDataSource;
};
export type DataSourceInjectionFunction = ((context: Record<string, unknown>) => DataSourceMap);
export interface IContextConfig {
namespace: string;
factory: ContextFunction;
}
export interface IContextWrapper extends ContextFunction {
use: (name: string | ContextFunction | null, fn?: ContextFunction | string) => void;
}
export interface IGraphQLComponentOptions<TContextType extends ComponentContext = ComponentContext> {
types?: TypeSource;
resolvers?: IResolvers<any, TContextType>;
mocks?: boolean | IMocks;
imports?: (IGraphQLComponent | IGraphQLComponentConfigObject)[];
context?: IContextConfig;
dataSources?: IDataSource[];
dataSourceOverrides?: IDataSource[];
pruneSchema?: boolean;
pruneSchemaOptions?: PruneSchemaOptions;
federation?: boolean;
transforms?: SchemaMapper[];
}
export interface IGraphQLComponent<TContextType extends ComponentContext = ComponentContext> {
readonly name: string;
readonly schema: GraphQLSchema;
readonly context: IContextWrapper;
readonly types: TypeSource;
readonly resolvers: IResolvers<any, TContextType>;
readonly imports?: (IGraphQLComponent | IGraphQLComponentConfigObject)[];
readonly dataSources?: IDataSource[];
readonly dataSourceOverrides?: IDataSource[];
federation?: boolean;
}
/**
* GraphQLComponent class for building modular GraphQL schemas
* @template TContextType - The type of the context object
* @implements {IGraphQLComponent}
*/
export default class GraphQLComponent<TContextType extends ComponentContext = ComponentContext> implements IGraphQLComponent {
_schema: GraphQLSchema;
_types: TypeSource;
_resolvers: IResolvers<any, TContextType>;
_mocks: boolean | IMocks;
_imports: IGraphQLComponentConfigObject[];
_context: ContextFunction;
_dataSources: IDataSource[];
_dataSourceOverrides: IDataSource[];
_pruneSchema: boolean;
_pruneSchemaOptions: PruneSchemaOptions;
_federation: boolean;
_dataSourceContextInject: DataSourceInjectionFunction;
_transforms: SchemaMapper[];
private _transformedSchema;
constructor({ types, resolvers, mocks, imports, context, dataSources, dataSourceOverrides, pruneSchema, pruneSchemaOptions, federation, transforms }: IGraphQLComponentOptions);
get context(): IContextWrapper;
get name(): string;
get schema(): GraphQLSchema;
get types(): TypeSource;
get resolvers(): IResolvers<any, TContextType>;
get imports(): IGraphQLComponentConfigObject[];
get dataSources(): IDataSource[];
get dataSourceOverrides(): IDataSource[];
set federation(flag: boolean);
get federation(): boolean;
dispose(): void;
private transformSchema;
private validateConfig;
}
Loading