Skip to content
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

fix: ignore @external on all entity extension key fields #1426

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
493 changes: 250 additions & 243 deletions composition-go/index.global.js

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions composition/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,10 @@ const subgraphA: Subgraph = {
| definitions | an AST representation of the subgraph SDL | graphql.DocumentNode |

### Contributing
Some GraphQL and Federation jargon should begin with a capitalised letter for clarity, e.g.,:
- Argument
When adding or changing error, please ensure GraphQL types begin with a capital letter for clarity:
- Enum
- Field
- Input Object
- Interface
- Object
When adding or changing errors, please begin these terms with a capital letter.
- Scalar
- Union
3 changes: 2 additions & 1 deletion composition/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"test:watch": "vitest test",
"test": "vitest run",
"lint": "prettier --check src tests",
"lint:fix": "prettier --write src tests"
"lint:fix": "prettier --write src tests",
"postversion": "node ./scripts/get-composition-version.mjs"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
20 changes: 20 additions & 0 deletions composition/scripts/get-composition-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import fs from 'fs';
import { fileURLToPath } from 'node:url';
import path from "node:path";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compositionVersion = '{{$COMPOSITION__VERSION}}';

// From pnpm v10+, hooks will not be supported.
if (process.argv[1] === __filename) {
const json = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json')).toString());
const version = json.version;
const varFilePath = path.join(__dirname, '../dist/utils/composition-version.js');
let content = fs.readFileSync(varFilePath).toString();
if (content.indexOf(compositionVersion) < 0) {
throw new Error(`"${compositionVersion}" string not found in dist/utils/composition-version.js.`);
}
content = content.replace(compositionVersion, version);
fs.writeFileSync(varFilePath, content);
}
40 changes: 2 additions & 38 deletions composition/src/ast/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
EnumTypeDefinitionNode,
EnumTypeExtensionNode,
FieldNode,
InlineFragmentNode,
InputObjectTypeDefinitionNode,
InputObjectTypeExtensionNode,
InterfaceTypeDefinitionNode,
Expand All @@ -23,8 +22,6 @@ import {
SelectionNode,
SelectionSetNode,
StringValueNode,
TypeDefinitionNode,
TypeExtensionNode,
UnionTypeDefinitionNode,
UnionTypeExtensionNode,
} from 'graphql';
Expand All @@ -33,7 +30,6 @@ import {
ENUM_UPPER,
ENUM_VALUE_UPPER,
EXECUTABLE_DIRECTIVE_LOCATIONS,
EXTENDS,
FIELD_DEFINITION_UPPER,
FRAGMENT_DEFINITION_UPPER,
FRAGMENT_SPREAD_UPPER,
Expand All @@ -52,7 +48,6 @@ import {
SUBSCRIPTION,
UNION_UPPER,
} from '../utils/string-constants';
import { duplicateImplementedInterfaceError } from '../errors/errors';
import { CompositeOutputNode } from '../schema-building/ast';

export function isObjectLikeNodeEntity(node: CompositeOutputNode): boolean {
Expand All @@ -79,37 +74,6 @@ export function isNodeInterfaceObject(node: ObjectTypeDefinitionNode): boolean {
return false;
}

export function isNodeExtension(node: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode): boolean {
if (!node.directives?.length) {
return false;
}
for (const directive of node.directives) {
if (directive.name.value === EXTENDS) {
return true;
}
}
return false;
}

export function areBaseAndExtensionKindsCompatible(baseKind: Kind, extensionKind: Kind, typeName: string): boolean {
switch (baseKind) {
case Kind.ENUM_TYPE_DEFINITION:
return extensionKind === Kind.ENUM_TYPE_EXTENSION;
case Kind.INPUT_OBJECT_TYPE_DEFINITION:
return extensionKind === Kind.INPUT_OBJECT_TYPE_EXTENSION;
case Kind.INTERFACE_TYPE_DEFINITION:
return extensionKind === Kind.INTERFACE_TYPE_EXTENSION;
case Kind.OBJECT_TYPE_DEFINITION:
return extensionKind === Kind.OBJECT_TYPE_EXTENSION;
case Kind.SCALAR_TYPE_DEFINITION:
return extensionKind === Kind.SCALAR_TYPE_EXTENSION;
case Kind.UNION_TYPE_DEFINITION:
return extensionKind === Kind.UNION_TYPE_EXTENSION;
default:
return false;
}
}

export function stringToNameNode(value: string): NameNode {
return {
kind: Kind.NAME,
Expand Down Expand Up @@ -311,8 +275,8 @@ export function parse(source: string, noLocation = true): DocumentNode {

export function safeParse(value: string, noLocation = true): ParseResult {
try {
const parsedValue = parse(value, noLocation);
return { documentNode: parsedValue };
const documentNode = parse(value, noLocation);
return { documentNode };
} catch (e) {
return { error: e as Error };
}
Expand Down
Loading
Loading