Skip to content

Commit

Permalink
fix: initialize arrays to string value
Browse files Browse the repository at this point in the history
Arrays are stored as strings in the database so we have to initialize
them as such as well.
  • Loading branch information
Sekhmet committed Nov 8, 2024
1 parent e394fb1 commit ac5192a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const getTypeInfo = (
const nonNullNestedType =
type.ofType instanceof GraphQLNonNull ? type.ofType.ofType : type.ofType;

return { type: `${getTypeInfo(nonNullNestedType, decimalTypes).type}[]`, initialValue: [] };
return { type: `${getTypeInfo(nonNullNestedType, decimalTypes).type}[]`, initialValue: '[]' };
}

throw new Error('Unknown type');
Expand Down
8 changes: 4 additions & 4 deletions test/unit/__snapshots__/codegen.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export class Space extends Model {
this.initialSet('voting_delay', 0);
this.initialSet('proposal_threshold', 0);
this.initialSet('quorum', 0);
this.initialSet('strategies', []);
this.initialSet('strategies_nonnull', []);
this.initialSet('strategies', "[]");
this.initialSet('strategies_nonnull', "[]");
}
static async loadEntity(id) {
Expand Down Expand Up @@ -217,8 +217,8 @@ export class Space extends Model {
this.initialSet('voting_delay', 0);
this.initialSet('proposal_threshold', 0);
this.initialSet('quorum', 0);
this.initialSet('strategies', []);
this.initialSet('strategies_nonnull', []);
this.initialSet('strategies', "[]");
this.initialSet('strategies_nonnull', "[]");
}
static async loadEntity(id: string): Promise<Space | null> {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/codegen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ describe('getInitialValue', () => {
expect(getInitialValue(proposalFields['active'].type)).toBe(false);
});

it('should return empty array for List types', () => {
expect(getInitialValue(spaceFields['strategies'].type)).toEqual([]);
expect(getInitialValue(spaceFields['strategies_nonnull'].type)).toEqual([]);
it('should return stringified empty array for List types', () => {
expect(getInitialValue(spaceFields['strategies'].type)).toEqual('[]');
expect(getInitialValue(spaceFields['strategies_nonnull'].type)).toEqual('[]');
});

it('should return empty string for object types', () => {
Expand Down

0 comments on commit ac5192a

Please sign in to comment.