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

chore: typescript-redux followups #656

Merged
merged 21 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e715ab6
Refine / split metadata types (instead of ? -> !)
trevor-scheer Apr 8, 2021
bdad209
getJoins -> getJoinDefinitions
trevor-scheer Apr 8, 2021
b3bb32e
sanitizedServiceNames -> graphNameToEnumValueName
trevor-scheer Apr 8, 2021
afd924c
Address enum sanitization/uniquification comments
trevor-scheer Apr 12, 2021
5bd3f10
Use actual map for GraphMap instead to account for undefined-ness
trevor-scheer Apr 13, 2021
4378987
Clean up usages of printWithReducedWhitespace in favor of stripIgnore…
trevor-scheer Apr 13, 2021
5e40df8
Confirm parsed FieldSets do not have an injected operation
trevor-scheer Apr 15, 2021
e37e2a6
Ensure no FragmentSpreads nested in a FieldSet
trevor-scheer Apr 15, 2021
2aa3cf5
Capture caveats in comments from commit messages
trevor-scheer Apr 15, 2021
fb0f6e9
Remove incorrect nullish coalesce to ownerService
trevor-scheer Apr 15, 2021
5ac14f2
Update ordering of join__Graph enum in test mocks
trevor-scheer Apr 16, 2021
7784276
Invert metadata predicate which was always negated to its opposite
trevor-scheer Apr 21, 2021
4b7d50f
Update expectations comment
trevor-scheer Apr 21, 2021
6c4261b
Create nice helper for working with Maps (mapGetOrSet)
trevor-scheer Apr 21, 2021
524809d
Fix usage of mapGetOrSet
trevor-scheer Apr 21, 2021
208a041
Add clarity to names
trevor-scheer Apr 21, 2021
f85a597
Correct error message
trevor-scheer Apr 21, 2021
2a2c429
Simplify extra } error message
trevor-scheer Apr 21, 2021
a1156a8
Fix remaining accesses to context.graphNameToEnumValueName
trevor-scheer Apr 21, 2021
53e0ad5
Update changelogs
trevor-scheer Apr 22, 2021
fe2c2aa
Merge branch 'main' into trevor/redux-followups
trevor-scheer Apr 22, 2021
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
7 changes: 1 addition & 6 deletions gateway-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,12 +695,7 @@ export class ApolloGateway implements GraphQLService {
throw Error(`Couldn't find graph map in composed schema`);
}

const serviceList = Object.values(graphMap).map(graph => ({
name: graph.name,
url: graph.url
}))

return serviceList;
return Array.from(graphMap.values());
}

private createSchemaFromSupergraphSdl(supergraphSdl: string) {
Expand Down
44 changes: 29 additions & 15 deletions query-planner-js/src/composedSchema/buildComposedSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function buildComposedSchema(document: DocumentNode): GraphQLSchema {
const graphEnumType = schema.getType(`${joinName}__Graph`);
assert(isEnumType(graphEnumType), `${joinName}__Graph should be an enum`);

const graphMap: GraphMap = Object.create(null);
const graphMap: GraphMap = new Map();
trevor-scheer marked this conversation as resolved.
Show resolved Hide resolved

schema.extensions = {
...schema.extensions,
Expand All @@ -108,10 +108,10 @@ export function buildComposedSchema(document: DocumentNode): GraphQLSchema {
const graphName: string = graphDirectiveArgs['name'];
const url: string = graphDirectiveArgs['url'];

graphMap[name] = {
graphMap.set(name, {
name: graphName,
url,
};
});
}

for (const type of Object.values(schema.getTypeMap())) {
Expand All @@ -130,15 +130,24 @@ export function buildComposedSchema(document: DocumentNode): GraphQLSchema {
type.astNode,
);

const typeMetadata: FederationTypeMetadata = ownerDirectiveArgs
? {
graphName: graphMap[ownerDirectiveArgs?.['graph']].name,
keys: new MultiMap(),
isValueType: false,
}
: {
isValueType: true,
};
let typeMetadata: FederationTypeMetadata;
if (ownerDirectiveArgs) {
const graph = graphMap.get(ownerDirectiveArgs.graph);
assert(
graph,
`@${ownerDirective.name} directive requires a \`graph\` argument`,
trevor-scheer marked this conversation as resolved.
Show resolved Hide resolved
);

typeMetadata = {
graphName: graph.name,
keys: new MultiMap(),
isValueType: false,
};
} else {
typeMetadata = {
isValueType: true,
};
}

type.extensions = {
...type.extensions,
Expand All @@ -160,14 +169,19 @@ directive without an @${ownerDirective.name} directive`,
);

for (const typeDirectiveArgs of typeDirectivesArgs) {
const graphName = graphMap[typeDirectiveArgs['graph']].name;
const graph = graphMap.get(typeDirectiveArgs.graph);

assert(
graph,
`GraphQL type "${type.name}" must provide a \`graph\` argument to the @${typeDirective.name} directive`,
trevor-scheer marked this conversation as resolved.
Show resolved Hide resolved
);

const keyFields = parseFieldSet(typeDirectiveArgs['key']);

// We know we won't actually be looping here in the case of a value type
// based on the assertion above, but TS is not able to infer that.
(typeMetadata as FederationEntityTypeMetadata).keys.add(
graphName,
graph.name,
keyFields,
);
}
Expand All @@ -186,7 +200,7 @@ directive without an @${ownerDirective.name} directive`,
if (!fieldDirectiveArgs) continue;

const fieldMetadata: FederationFieldMetadata = {
graphName: graphMap[fieldDirectiveArgs?.['graph']]?.name,
graphName: graphMap.get(fieldDirectiveArgs.graph)?.name,
trevor-scheer marked this conversation as resolved.
Show resolved Hide resolved
};

fieldDef.extensions = {
Expand Down
2 changes: 1 addition & 1 deletion query-planner-js/src/composedSchema/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface Graph {
url: string;
}

export type GraphMap = { [graphName: string]: Graph };
export type GraphMap = Map<string, Graph>;
export interface FederationSchemaMetadata {
graphs: GraphMap;
}
Expand Down