Skip to content

Commit

Permalink
docs: add jsdocs for plugins and fieldUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
hayes committed Jun 11, 2021
1 parent 3a064a8 commit bfe383b
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 46 deletions.
55 changes: 55 additions & 0 deletions packages/core/src/fieldUtils/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export default class FieldBuilder<
ParentShape,
Kind extends Exclude<FieldKind, RootName> = Exclude<FieldKind, RootName>,
> extends RootFieldBuilder<Types, ParentShape, Kind> {
/**
* Create a Boolean field from a boolean property on the parent object
* @param {string} name - the name of the property on the source object (does not need to match the field name).
* @param {object} [options={}] - Options for this field
*/
exposeBoolean<
Name extends CompatibleTypes<Types, ParentShape, 'Boolean', Nullable>,
ResolveReturnShape,
Expand Down Expand Up @@ -44,6 +49,11 @@ export default class FieldBuilder<
return this.exposeField<'Boolean', Nullable, Name>(name, { ...options, type: 'Boolean' });
}

/**
* Create a Float field from a numeric property on the parent object
* @param {string} name - the name of the property on the source object (does not need to match the field name).
* @param {object} [options={}] - Options for this field
*/
exposeFloat<
Name extends CompatibleTypes<Types, ParentShape, 'Float', Nullable>,
ResolveReturnShape,
Expand Down Expand Up @@ -73,6 +83,11 @@ export default class FieldBuilder<
return this.exposeField<'Float', Nullable, Name>(name, { ...options, type: 'Float' });
}

/**
* Create an ID field from a property on the parent object
* @param {string} name - the name of the property on the source object (does not need to match the field name).
* @param {object} [options={}] - Options for this field
*/
exposeID<
Name extends CompatibleTypes<Types, ParentShape, 'ID', Nullable>,
ResolveReturnShape,
Expand Down Expand Up @@ -102,6 +117,11 @@ export default class FieldBuilder<
return this.exposeField<'ID', Nullable, Name>(name, { ...options, type: 'ID' });
}

/**
* Create an Int field from a numeric property on the parent object
* @param {string} name - the name of the property on the source object (does not need to match the field name).
* @param {object} [options={}] - Options for this field
*/
exposeInt<
Name extends CompatibleTypes<Types, ParentShape, 'Int', Nullable>,
ResolveReturnShape,
Expand Down Expand Up @@ -131,6 +151,11 @@ export default class FieldBuilder<
return this.exposeField<'Int', Nullable, Name>(name, { ...options, type: 'Int' });
}

/**
* Create a String field from a string property on the parent object
* @param {string} name - the name of the property on the source object (does not need to match the field name).
* @param {object} [options={}] - Options for this field
*/
exposeString<
Name extends CompatibleTypes<Types, ParentShape, 'String', Nullable>,
ResolveReturnShape,
Expand Down Expand Up @@ -160,6 +185,11 @@ export default class FieldBuilder<
return this.exposeField<'String', Nullable, Name>(name, { ...options, type: 'String' });
}

/**
* Create a Boolean list field from a boolean[] property on the parent object
* @param {string} name - the name of the property on the source object (does not need to match the field name).
* @param {object} [options={}] - Options for this field
*/
exposeBooleanList<
Name extends CompatibleTypes<Types, ParentShape, ['Boolean'], Nullable>,
ResolveReturnShape,
Expand Down Expand Up @@ -189,6 +219,11 @@ export default class FieldBuilder<
return this.exposeField<['Boolean'], Nullable, Name>(name, { ...options, type: ['Boolean'] });
}

/**
* Create a Float list field from a number[] property on the parent object
* @param {string} name - the name of the property on the source object (does not need to match the field name).
* @param {object} [options={}] - Options for this field
*/
exposeFloatList<
Name extends CompatibleTypes<Types, ParentShape, ['Float'], Nullable>,
ResolveReturnShape,
Expand Down Expand Up @@ -218,6 +253,11 @@ export default class FieldBuilder<
return this.exposeField<['Float'], Nullable, Name>(name, { ...options, type: ['Float'] });
}

/**
* Create an ID list field from an id[] property on the parent object
* @param {string} name - the name of the property on the source object (does not need to match the field name).
* @param {object} [options={}] - Options for this field
*/
exposeIDList<
Name extends CompatibleTypes<Types, ParentShape, ['ID'], Nullable>,
ResolveReturnShape,
Expand Down Expand Up @@ -247,6 +287,11 @@ export default class FieldBuilder<
return this.exposeField<['ID'], Nullable, Name>(name, { ...options, type: ['ID'] });
}

/**
* Create a Int list field from a number[] property on the parent object
* @param {string} name - the name of the property on the source object (does not need to match the field name).
* @param {object} [options={}] - Options for this field
*/
exposeIntList<
Name extends CompatibleTypes<Types, ParentShape, ['Int'], Nullable>,
ResolveReturnShape,
Expand Down Expand Up @@ -276,6 +321,11 @@ export default class FieldBuilder<
return this.exposeField<['Int'], Nullable, Name>(name, { ...options, type: ['Int'] });
}

/**
* Create a String list field from a string[] property on the parent object
* @param {string} name - the name of the property on the source object (does not need to match the field name).
* @param {object} [options={}] - Options for this field
*/
exposeStringList<
Name extends CompatibleTypes<Types, ParentShape, ['String'], Nullable>,
ResolveReturnShape,
Expand Down Expand Up @@ -305,6 +355,11 @@ export default class FieldBuilder<
return this.exposeField<['String'], Nullable, Name>(name, { ...options, type: ['String'] });
}

/**
* Create a field that resolves to a property of the corresponding type on the parent object
* @param {string} name - the name of the property on the source object (does not need to match the field name).
* @param {object} [options={}] - Options for this field
*/
expose<
Type extends TypeParam<Types>,
Nullable extends boolean,
Expand Down
44 changes: 44 additions & 0 deletions packages/core/src/fieldUtils/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,64 @@ export default class InputFieldBuilder<

typename: string;

/**
* Create a Boolean input field
* @param {GiraphQLSchemaTypes.InputFieldOptions} [options={}] - Options for this field
*/
boolean = this.helper('Boolean');

/**
* Create a Float input field
* @param {GiraphQLSchemaTypes.InputFieldOptions} [options={}] - Options for this field
*/
float = this.helper('Float');

/**
* Create a ID input field
* @param {GiraphQLSchemaTypes.InputFieldOptions} [options={}] - Options for this field
*/
id = this.helper('ID');

/**
* Create a Int input field
* @param {GiraphQLSchemaTypes.InputFieldOptions} [options={}] - Options for this field
*/
int = this.helper('Int');

/**
* Create a String input field
* @param {GiraphQLSchemaTypes.InputFieldOptions} [options={}] - Options for this field
*/
string = this.helper('String');

/**
* Create a Boolean list input field
* @param {GiraphQLSchemaTypes.InputFieldOptions} [options={}] - Options for this field
*/
booleanList = this.helper(['Boolean']);

/**
* Create a Float list input field
* @param {GiraphQLSchemaTypes.InputFieldOptions} [options={}] - Options for this field
*/
floatList = this.helper(['Float']);

/**
* Create a ID list input field
* @param {GiraphQLSchemaTypes.InputFieldOptions} [options={}] - Options for this field
*/
idList = this.helper(['ID']);

/**
* Create a Int list input field
* @param {GiraphQLSchemaTypes.InputFieldOptions} [options={}] - Options for this field
*/
intList = this.helper(['Int']);

/**
* Create a String list input field
* @param {GiraphQLSchemaTypes.InputFieldOptions} [options={}] - Options for this field
*/
stringList = this.helper(['String']);

constructor(builder: GiraphQLSchemaTypes.SchemaBuilder<Types>, kind: Kind, typename: string) {
Expand Down Expand Up @@ -64,6 +104,10 @@ export default class InputFieldBuilder<
return builder as ArgBuilder<Types>;
}

/**
* Create in input field or argument for the current type
* @param {GiraphQLSchemaTypes.InputFieldOptions} [options={}] - Options for this field
*/
field<Type extends InputType<Types> | [InputType<Types>], Req extends FieldRequiredness<Type>>(
options: GiraphQLSchemaTypes.InputFieldOptionsByKind<Types, Type, Req>[Kind],
) {
Expand Down
47 changes: 44 additions & 3 deletions packages/core/src/fieldUtils/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export default class RootFieldBuilder<
this.typename,
).argBuilder();

/**
* Create a Boolean field
* @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field
*/
boolean<
Args extends InputFieldMap,
ResolveShape,
Expand Down Expand Up @@ -53,6 +57,10 @@ export default class RootFieldBuilder<
});
}

/**
* Create a Float field
* @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field
*/
float<
Args extends InputFieldMap,
Nullable extends FieldNullability<'Float'>,
Expand Down Expand Up @@ -85,6 +93,10 @@ export default class RootFieldBuilder<
});
}

/**
* Create a ID field
* @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field
*/
id<
Args extends InputFieldMap,
Nullable extends FieldNullability<'ID'>,
Expand Down Expand Up @@ -114,6 +126,10 @@ export default class RootFieldBuilder<
return this.createField<Args, 'ID', Nullable>({ ...options, type: 'ID' });
}

/**
* Create a Int field
* @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field
*/
int<
Args extends InputFieldMap,
Nullable extends FieldNullability<'Int'>,
Expand Down Expand Up @@ -143,6 +159,10 @@ export default class RootFieldBuilder<
return this.createField<Args, 'Int', Nullable>({ ...options, type: 'Int' });
}

/**
* Create a String field
* @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field
*/
string<
Args extends InputFieldMap,
ResolveShape,
Expand Down Expand Up @@ -175,6 +195,10 @@ export default class RootFieldBuilder<
});
}

/**
* Create a Boolean list field
* @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field
*/
booleanList<
Args extends InputFieldMap,
ResolveShape,
Expand Down Expand Up @@ -204,6 +228,10 @@ export default class RootFieldBuilder<
return this.createField<Args, ['Boolean'], Nullable>({ ...options, type: ['Boolean'] });
}

/**
* Create a Float list field
* @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field
*/
floatList<
Args extends InputFieldMap,
ResolveShape,
Expand Down Expand Up @@ -233,6 +261,10 @@ export default class RootFieldBuilder<
return this.createField<Args, ['Float'], Nullable>({ ...options, type: ['Float'] });
}

/**
* Create a ID list field
* @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field
*/
idList<
Args extends InputFieldMap,
Nullable extends FieldNullability<['ID']>,
Expand Down Expand Up @@ -262,6 +294,10 @@ export default class RootFieldBuilder<
return this.createField<Args, ['ID'], Nullable>({ ...options, type: ['ID'] });
}

/**
* Create a Int list field
* @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field
*/
intList<
Args extends InputFieldMap,
ResolveShape,
Expand Down Expand Up @@ -291,6 +327,10 @@ export default class RootFieldBuilder<
return this.createField<Args, ['Int'], Nullable>({ ...options, type: ['Int'] });
}

/**
* Create a String list field
* @param {GiraphQLSchemaTypes.FieldOptions} options - Options for this field
*/
stringList<
Args extends InputFieldMap,
ResolveShape,
Expand Down Expand Up @@ -320,9 +360,10 @@ export default class RootFieldBuilder<
return this.createField<Args, ['String'], Nullable>({ ...options, type: ['String'] });
}

/** create a new field for the current type
@param {GiraphQLSchemaTypes.FieldOptions} options - options for this field
*/
/**
* create a new field for the current type
* @param {GiraphQLSchemaTypes.FieldOptions} options - options for this field
*/
field<
Args extends InputFieldMap,
Type extends TypeParam<Types>,
Expand Down

0 comments on commit bfe383b

Please sign in to comment.