Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
Fixing list mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Cooke committed Apr 3, 2017
1 parent e3c4e66 commit 603baac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/testGenerate.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export type Single = {|
objectListField: Array<{|
stringField: string
|}>,
nullableEmptyObjectListField: null | {||},
emptyObjectListField: {||}
nullableEmptyObjectListField: null | Array<{||}>,
emptyObjectListField: Array<{||}>
|};
export type Duplicate1 = {|
Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/testParse.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@ Relay.QL\`query {
});
});

it('should handle empty lists of items', () => {
expect(parse(`
Relay.QL\`
fragment on User {
todos {
\${SomeComponent.getFragment('todos')}
}
}
\`
`, schema)).toEqual({
UserFragmentType: [
{
todos: {type: 'list', ofType: {type: 'object', object: {}, nonNull: true}, nonNull: true}
}
]
});
});

it('should handle variables included as fragments', () => {
expect(parse(`
Relay.QL\`
Expand Down
7 changes: 1 addition & 6 deletions src/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ function fieldType(field, indent) {

switch (field.type) {
case 'list':
if (field.ofType.type === 'object' && !Object.keys(field.ofType.object).length) {
// If there are no selections we want an opaque object even if it is a list
flowType = `{||}`;
} else {
flowType = `Array<${fieldType(field.ofType, indent)}>`;
}
flowType = `Array<${fieldType(field.ofType, indent)}>`;
break;
case 'object':
flowType = objectType(field.object, `${indent}${INDENT}`);
Expand Down

0 comments on commit 603baac

Please sign in to comment.