Skip to content

Commit

Permalink
Sort fragment arguments, updated artifacts
Browse files Browse the repository at this point in the history
Reviewed By: tyao1

Differential Revision: D21892665

fbshipit-source-id: f594acb412f234e4ec8e4f6dc1fbe231b729c3fa
  • Loading branch information
alunyov authored and facebook-github-bot committed Jun 5, 2020
1 parent 9e29299 commit b065ae2
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 108 deletions.
49 changes: 29 additions & 20 deletions packages/relay-compiler/codegen/ReaderCodeGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import type {
ReaderInlineDataFragmentSpread,
ReaderLinkedField,
ReaderModuleImport,
ReaderRefetchMetadata,
ReaderScalarField,
ReaderSelection,
} from 'relay-runtime';
Expand Down Expand Up @@ -158,25 +157,35 @@ function generateArgumentDefinitions(
schema: Schema,
nodes: $ReadOnlyArray<ArgumentDefinition>,
): $ReadOnlyArray<ReaderArgumentDefinition> {
return nodes.map(node => {
switch (node.kind) {
case 'LocalArgumentDefinition':
return {
defaultValue: node.defaultValue,
kind: 'LocalArgument',
name: node.name,
type: schema.getTypeString(node.type),
};
case 'RootArgumentDefinition':
return {
kind: 'RootArgument',
name: node.name,
type: node.type ? schema.getTypeString(node.type) : null,
};
default:
throw new Error();
}
});
return nodes
.map(node => {
switch (node.kind) {
case 'LocalArgumentDefinition':
return {
defaultValue: node.defaultValue,
kind: 'LocalArgument',
name: node.name,
type: schema.getTypeString(node.type),
};
case 'RootArgumentDefinition':
return {
kind: 'RootArgument',
name: node.name,
type: node.type ? schema.getTypeString(node.type) : null,
};
default:
throw new Error();
}
})
.sort((nodeA, nodeB) => {
if (nodeA.name > nodeB.name) {
return 1;
}
if (nodeA.name < nodeB.name) {
return -1;
}
return 0;
});
}

function generateClientExtension(
Expand Down
Loading

0 comments on commit b065ae2

Please sign in to comment.