Skip to content

Commit 62d6f93

Browse files
authored
Merge pull request #791 from graphprotocol/otavio/fix-schema-primitives
codegen: Remove default values for primitive schema fields
2 parents 77546f3 + 7e4ade6 commit 62d6f93

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphprotocol/graph-cli",
3-
"version": "0.25.0",
3+
"version": "0.25.1",
44
"description": "CLI for building for and deploying to The Graph",
55
"dependencies": {
66
"assemblyscript": "0.19.10",

src/codegen/schema.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,24 @@ module.exports = class SchemaCodeGenerator {
8080
.map(field => {
8181
const name = field.getIn(['name', 'value'])
8282
const type = this._typeFromGraphQl(field.get('type'))
83+
8384
const isNullable = type instanceof tsCodegen.NullableType
85+
const isPrimitive = type.isPrimitive && type.isPrimitive()
8486

8587
const directives = field.get('directives')
8688
const isDerivedFrom = directives.some(directive => directive.getIn(['name', 'value']) === 'derivedFrom')
8789

88-
return { name, type, isNullable, isDerivedFrom }
90+
return { name, type, isNullable, isPrimitive, isDerivedFrom }
8991
})
9092
// We only call the setter with the default value in the constructor for fields that are:
93+
// - Not primitive (such as Int/i32)
9194
// - Not nullable, so that AS doesn't break when subgraph developers try to access them before a `set`
9295
// - Not tagged as `derivedFrom`, because they only exist in query time
93-
.filter(({ isNullable, isDerivedFrom }) => !isNullable && !isDerivedFrom)
96+
.filter(({
97+
isNullable,
98+
isPrimitive,
99+
isDerivedFrom,
100+
}) => !(isNullable || isPrimitive || isDerivedFrom))
94101
.map(({ name, type, isNullable }) => {
95102
const fieldTypeString = isNullable ? type.inner.toString() : type.toString()
96103

0 commit comments

Comments
 (0)