Skip to content

Commit

Permalink
fix: json list codegen issues (Joystream#125)
Browse files Browse the repository at this point in the history
* fix: json list codegen issues

affects: @subsquid/hydra-cli, hydra-e2e-tests

* style: fix lint errors

affects: @subsquid/hydra-cli, hydra-e2e-tests
  • Loading branch information
eldargab authored Oct 18, 2021
1 parent 14bd1eb commit 9989361
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/hydra-cli/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function generateOrmModels(model: Model, dir: OutDir): void {
)}, from: obj => ${marshalFromJson(
prop,
'obj'
)}}, nullable: ${prop.nullable})`
)}}, nullable: ${prop.nullable}})`
)
break
default:
Expand Down Expand Up @@ -330,7 +330,10 @@ function generateOrmModels(model: Model, dir: OutDir): void {
convert = exp + '.toJSON()'
break
case 'list':
convert = `${exp}.map(val => ${marshalToJson(prop.type.item, 'val')})`
convert = `${exp}.map((val: any) => ${marshalToJson(
prop.type.item,
'val'
)})`
break
default:
throw unsupportedCase(prop.type.kind)
Expand Down
1 change: 1 addition & 0 deletions packages/hydra-e2e-tests/fixtures/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type EventB implements Event @entity {
network: Network!
indexInBlock: Int!
field2: String!
statusList: [Status!]
}

type EventC implements Event @entity {
Expand Down
2 changes: 2 additions & 0 deletions packages/hydra-e2e-tests/fixtures/src/mappings/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
EventParam,
Network,
SystemEvent,
HappyPoor,
} from '../generated/model'

export async function loader(ctx: BlockContext & StoreContext) {
Expand All @@ -33,6 +34,7 @@ export async function eventLoader({ store }: BlockContext & StoreContext) {
network: Network.BABYLON,
indexInBlock: 1,
field2: 'field2',
statusList: [new HappyPoor({ isMale: true })],
})

const ce = new ComplexEntity()
Expand Down
23 changes: 23 additions & 0 deletions packages/hydra-e2e-tests/test/jsonfields-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,27 @@ describe('end-to-end json fields tests', () => {
}
)
})

it('fetch json list', () => {
return queryNode.test(
`
query {
eventBs {
statusList {
... on HappyPoor {
isMale
}
}
}
}
`,
{
eventBs: [
{
statusList: [{ isMale: true }],
},
],
}
)
})
})

0 comments on commit 9989361

Please sign in to comment.