-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor logic to define call arguments so they are automatically ord…
…ered correctly
- Loading branch information
1 parent
0a6fac2
commit 8b30030
Showing
12 changed files
with
182 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"eth-graphql": patch | ||
--- | ||
|
||
Fix issue with argument order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const ROOT_FIELD_NAME = 'contracts'; | ||
export const ROOT_FIELD_SINGLE_ARGUMENT_NAME = 'addresses'; | ||
export const MULT_FIELD_SUFFIX = '_MULT'; | ||
export const MULT_FIELD_SINGLE_ARGUMENT_NAME = 'args'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...aphql/src/createSchema/makeCalls/__tests__/__snapshots__/formatArgumentNodes.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`createSchema/makeCalls/formatArgumentNodes converts argument nodes to valid arguments 1`] = ` | ||
{ | ||
"fake name 0": [ | ||
[ | ||
"fake string 0", | ||
], | ||
], | ||
"fake name 1": { | ||
"fake name 2": { | ||
"fake name 3": "fake string 1", | ||
}, | ||
}, | ||
"fake name 4": "fake string 2", | ||
"fake name 5": true, | ||
"fake name 6": "100", | ||
"fake name 7": "0", | ||
"fake name 8": "fake variable value", | ||
} | ||
`; |
22 changes: 0 additions & 22 deletions
22
...graphql/src/createSchema/makeCalls/__tests__/__snapshots__/formatGraphQlArgs.test.ts.snap
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/eth-graphql/src/createSchema/makeCalls/formatArgumentNodes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { ArgumentNode, GraphQLResolveInfo, Kind, ValueNode } from 'graphql'; | ||
|
||
import { SolidityValue } from '../../types'; | ||
import { ContractCallArgs } from './types'; | ||
|
||
// Extract a node's value | ||
const getNodeValue = ({ | ||
valueNode, | ||
variableValues, | ||
}: { | ||
valueNode: ValueNode; | ||
variableValues: GraphQLResolveInfo['variableValues']; | ||
}): SolidityValue => { | ||
if (valueNode.kind === Kind.NULL) { | ||
return null; | ||
} | ||
|
||
// Get variable node value | ||
if (valueNode.kind === Kind.VARIABLE) { | ||
const variableName = valueNode.name.value; | ||
return variableValues[variableName] as SolidityValue; | ||
} | ||
|
||
// Convert list to array | ||
if (valueNode.kind === Kind.LIST) { | ||
return valueNode.values.map(node => | ||
getNodeValue({ | ||
valueNode: node, | ||
variableValues, | ||
}), | ||
); | ||
} | ||
|
||
// Convert object to object | ||
if (valueNode.kind === Kind.OBJECT) { | ||
return valueNode.fields.reduce( | ||
(accObject, field) => ({ | ||
...accObject, | ||
[field.name.value]: getNodeValue({ | ||
valueNode: field.value, | ||
variableValues, | ||
}), | ||
}), | ||
{}, | ||
); | ||
} | ||
|
||
return valueNode.value; | ||
}; | ||
|
||
const formatArgumentNodes = ({ | ||
argumentNodes, | ||
variableValues, | ||
}: { | ||
argumentNodes: ReadonlyArray<ArgumentNode>; | ||
variableValues: GraphQLResolveInfo['variableValues']; | ||
}) => | ||
argumentNodes.reduce<ContractCallArgs>( | ||
(accArguments, argument) => ({ | ||
...accArguments, | ||
[argument.name.value]: getNodeValue({ | ||
valueNode: argument.value, | ||
variableValues, | ||
}), | ||
}), | ||
{}, | ||
); | ||
|
||
export default formatArgumentNodes; |
Oops, something went wrong.