示例#1
0
 public function setup()
 {
     $this->simpleMutation = Mutation::mutationWithClientMutationId(['name' => 'SimpleMutation', 'inputFields' => [], 'outputFields' => ['result' => ['type' => Type::int()]], 'mutateAndGetPayload' => function () {
         return ['result' => 1];
     }]);
     $this->simpleMutationWithThunkFields = Mutation::mutationWithClientMutationId(['name' => 'SimpleMutationWithThunkFields', 'inputFields' => function () {
         return ['inputData' => ['type' => Type::int()]];
     }, 'outputFields' => function () {
         return ['result' => ['type' => Type::int()]];
     }, 'mutateAndGetPayload' => function ($inputData) {
         return ['result' => $inputData['inputData']];
     }]);
     $userType = new ObjectType(['name' => 'User', 'fields' => ['name' => ['type' => Type::string()]]]);
     $this->edgeMutation = Mutation::mutationWithClientMutationId(['name' => 'EdgeMutation', 'inputFields' => [], 'outputFields' => ['result' => ['type' => Connection::createEdgeType(['nodeType' => $userType])]], 'mutateAndGetPayload' => function () {
         return ['result' => ['node' => ['name' => 'Robert'], 'cursor' => 'SWxvdmVHcmFwaFFM']];
     }]);
     $this->mutation = new ObjectType(['name' => 'Mutation', 'fields' => ['simpleMutation' => $this->simpleMutation, 'simpleMutationWithThunkFields' => $this->simpleMutationWithThunkFields, 'edgeMutation' => $this->edgeMutation]]);
     $this->schema = new Schema(['mutation' => $this->mutation, 'query' => $this->mutation]);
 }
示例#2
0
 /**
  * Returns a GraphQLFieldConfig for the mutation described by the
  * provided MutationConfig.
  *
  * A description of a mutation consumable by mutationWithClientMutationId
  * to create a GraphQLFieldConfig for that mutation.
  *
  * The inputFields and outputFields should not include `clientMutationId`,
  * as this will be provided automatically.
  *
  * An input object will be created containing the input fields, and an
  * object will be created containing the output fields.
  *
  * mutateAndGetPayload will receieve an Object with a key for each
  * input field, and it should return an Object with a key for each
  * output field. It may return synchronously, or return a Promise.
  *
  * type MutationConfig = {
  *   name: string,
  *   inputFields: InputObjectConfigFieldMap,
  *   outputFields: GraphQLFieldConfigMap,
  *   mutateAndGetPayload: mutationFn,
  * }
  *
  * @param array $config
  * @return array
  */
 public static function mutationWithClientMutationId(array $config)
 {
     return Mutation::mutationWithClientMutationId($config);
 }