schema: make `fields` and `clauses` exact (#843)

Summary:
This affords more flexibility to clients, because an exact value can be
used in place of an inexact value, but not vice versa.

Test Plan:
Running `yarn flow` suffices.

wchargin-branch: schema-exact-type-fields
This commit is contained in:
William Chargin 2018-09-17 12:07:52 -07:00 committed by GitHub
parent 1ad2cc0958
commit f966ce300f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -33,8 +33,8 @@ export type ObjectId = string;
// are not. // are not.
export type Schema = {+[Typename]: NodeType}; export type Schema = {+[Typename]: NodeType};
export type NodeType = export type NodeType =
| {|+type: "OBJECT", +fields: {+[Fieldname]: FieldType}|} | {|+type: "OBJECT", +fields: {|+[Fieldname]: FieldType|}|}
| {|+type: "UNION", +clauses: {+[Typename]: true}|}; | {|+type: "UNION", +clauses: {|+[Typename]: true|}|};
export type FieldType = export type FieldType =
| {|+type: "ID"|} | {|+type: "ID"|}
| {|+type: "PRIMITIVE"|} | {|+type: "PRIMITIVE"|}
@ -101,7 +101,7 @@ export function object(fields: {[Fieldname]: FieldType}): NodeType {
} }
export function union(clauses: $ReadOnlyArray<Typename>): NodeType { export function union(clauses: $ReadOnlyArray<Typename>): NodeType {
const clausesMap = {}; const clausesMap: {|[Typename]: true|} = ({}: any);
for (const clause of clauses) { for (const clause of clauses) {
if (clausesMap[clause] != null) { if (clausesMap[clause] != null) {
throw new Error(`duplicate union clause: "${clause}"`); throw new Error(`duplicate union clause: "${clause}"`);