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