Skip to content

Commit 2c75e9f

Browse files
authored
Merge branch 'master' into master
2 parents 4a1954e + a7d9f97 commit 2c75e9f

File tree

8 files changed

+622
-65
lines changed

8 files changed

+622
-65
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphprotocol/graph-cli",
3-
"version": "0.25.1",
3+
"version": "0.25.3",
44
"description": "CLI for building for and deploying to The Graph",
55
"dependencies": {
66
"assemblyscript": "0.19.10",
@@ -12,7 +12,7 @@
1212
"dockerode": "^2.5.8",
1313
"fs-extra": "^9.0.0",
1414
"glob": "^7.1.2",
15-
"gluegun": "^4.3.1",
15+
"gluegun": "https://github.com/edgeandnode/gluegun#v4.3.1-pin-colors-dep",
1616
"graphql": "^15.5.0",
1717
"immutable": "^3.8.2",
1818
"ipfs-http-client": "^34.0.0",

src/codegen/schema.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,23 @@ module.exports = class SchemaCodeGenerator {
7979
const fieldsSetCalls = fieldsWithoutId
8080
.map(field => {
8181
const name = field.getIn(['name', 'value'])
82-
const type = this._typeFromGraphQl(field.get('type'))
82+
const type = this._typeFromGraphQl(field.get('type'), true, true)
8383

8484
const isNullable = type instanceof tsCodegen.NullableType
85-
const isPrimitive = type.isPrimitive && type.isPrimitive()
8685

8786
const directives = field.get('directives')
8887
const isDerivedFrom = directives.some(directive => directive.getIn(['name', 'value']) === 'derivedFrom')
8988

90-
return { name, type, isNullable, isPrimitive, isDerivedFrom }
89+
return { name, type, isNullable, isDerivedFrom }
9190
})
9291
// We only call the setter with the default value in the constructor for fields that are:
93-
// - Not primitive (such as Int/i32)
9492
// - Not nullable, so that AS doesn't break when subgraph developers try to access them before a `set`
93+
// - It doesn't matter if it's primitive or not
9594
// - Not tagged as `derivedFrom`, because they only exist in query time
9695
.filter(({
9796
isNullable,
98-
isPrimitive,
9997
isDerivedFrom,
100-
}) => !(isNullable || isPrimitive || isDerivedFrom))
98+
}) => !isNullable && !isDerivedFrom)
10199
.map(({ name, type, isNullable }) => {
102100
const fieldTypeString = isNullable ? type.inner.toString() : type.toString()
103101

@@ -236,7 +234,7 @@ Suggestion: add an '!' to the member type of the List, change from '${fieldValue
236234
: gqlType.getIn(['name', 'value'])
237235
}
238236

239-
_typeFromGraphQl(gqlType, nullable = true) {
237+
_typeFromGraphQl(gqlType, nullable = true, nullablePrimitive = false) {
240238
if (gqlType.get('kind') === 'NonNullType') {
241239
return this._typeFromGraphQl(gqlType.get('type'), false)
242240
} else if (gqlType.get('kind') === 'ListType') {
@@ -247,8 +245,13 @@ Suggestion: add an '!' to the member type of the List, change from '${fieldValue
247245
let type = tsCodegen.namedType(
248246
typesCodegen.ascTypeForValue(gqlType.getIn(['name', 'value'])),
249247
)
250-
// In AssemblyScript, primitives cannot be nullable.
251-
return nullable && !type.isPrimitive() ? tsCodegen.nullableType(type) : type
248+
249+
// Will not wrap primitives into NullableType by default.
250+
if (!nullablePrimitive && type.isPrimitive()) {
251+
return type
252+
}
253+
254+
return nullable ? tsCodegen.nullableType(type) : type
252255
}
253256
}
254257
}

0 commit comments

Comments
 (0)