Skip to content

Commit

Permalink
feat(filter-transform): filter deprecated types or fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Dec 5, 2023
1 parent b6fa1c6 commit d758afa
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/dry-baboons-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphql-mesh/transform-filter-schema': patch
'@graphql-mesh/types': patch
---

`filterDeprecatedFields` and `filterDeprecatedTypes` options
37 changes: 36 additions & 1 deletion packages/transforms/filter-schema/src/wrapFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import {

export default class WrapFilter implements Transform {
private transforms: Transform[] = [];
constructor({ config: { filters } }: { config: YamlConfig.FilterSchemaTransform }) {
constructor({
config: { filters, filterDeprecatedFields, filterDeprecatedTypes },
}: {
config: YamlConfig.FilterSchemaTransform;
}) {
for (const filter of filters) {
const [typeName, fieldNameOrGlob, argsGlob] = filter.split('.');
const typeMatcher = new Minimatch(typeName);
Expand Down Expand Up @@ -108,6 +112,37 @@ export default class WrapFilter implements Transform {
}),
);
}
if (filterDeprecatedFields) {
this.transforms.push(
new FilterRootFields((_, fieldName, fieldConfig) => {
return !fieldConfig.deprecationReason;
}),
);
this.transforms.push(
new FilterObjectFields((_, fieldName, fieldConfig) => {
return !fieldConfig.deprecationReason;
}),
);
this.transforms.push(
new FilterInputObjectFields((_, fieldName, fieldConfig) => {
return !fieldConfig.deprecationReason;
}),
);
this.transforms.push(
new FilterInterfaceFields((_, fieldName, fieldConfig) => {
return !fieldConfig.deprecationReason;
}),
);
}
if (filterDeprecatedTypes) {
this.transforms.push(
new FilterTypes(type => {
return !type.astNode?.directives?.some(
directive => directive.name.value === 'deprecated',
);
}),
);
}
}

transformSchema(
Expand Down
8 changes: 8 additions & 0 deletions packages/transforms/filter-schema/yaml-config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ type FilterSchemaTransform @md {
Array of filter rules
"""
filters: [String!]!
"""
Filter deprecated types
"""
filterDeprecatedTypes: Boolean
"""
Filter deprecated fields
"""
filterDeprecatedFields: Boolean
}

enum FilterSchemaTransformMode {
Expand Down
8 changes: 8 additions & 0 deletions packages/types/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3436,6 +3436,14 @@
},
"additionalItems": false,
"description": "Array of filter rules"
},
"filterDeprecatedTypes": {
"type": "boolean",
"description": "Filter deprecated types"
},
"filterDeprecatedFields": {
"type": "boolean",
"description": "Filter deprecated fields"
}
},
"required": ["filters"]
Expand Down
8 changes: 8 additions & 0 deletions packages/types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,14 @@ export interface FilterSchemaTransform {
* Array of filter rules
*/
filters: string[];
/**
* Filter deprecated types
*/
filterDeprecatedTypes?: boolean;
/**
* Filter deprecated fields
*/
filterDeprecatedFields?: boolean;
}
export interface HoistFieldTransformConfig {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

* `mode` (type: `String (bare | wrap)`) - Specify to apply filter-schema transforms to bare schema or by wrapping original schema
* `filters` (type: `Array of String`, required) - Array of filter rules
* `filters` (type: `Array of String`, required) - Array of filter rules
* `filterDeprecatedTypes` (type: `Boolean`) - Filter deprecated types
* `filterDeprecatedFields` (type: `Boolean`) - Filter deprecated fields

0 comments on commit d758afa

Please sign in to comment.