2.0.0 • Published 4 years ago

react-apollo-forms v2.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

react-apollo-forms

<Button>

import React from 'react';
import { Button } from 'react-apollo-forms';
import mutation from './update.gql';

export const SaveButton = () => (
  <Button
    mutation={mutation}
    variables={{
      name: 'Barry Allen',
    }}
  >
    Change Name
  </Buttom>
);

<Input>

import React from 'react';
import { Input } from 'react-apollo-forms';
import mutation from './update.gql';

export const UserInput = () => (
  <Input
    type="text"
    mutation={mutation}
    value="Clark Kent"
    onChange={({
      target: {
        value: name,
      },
    }, mutate) => mutate({
      variables: {
        name,
      },
    })}
  />
);

<Textarea>

import React from 'react';
import { Textarea } from 'react-apollo-forms';
import mutation from './update.gql';

export const DescriptionInput = () => (
  <Textarea
    type="text"
    mutation={mutation}
    value="Bruce Wayne"
    onChange={({
      target: {
        value: description,
      },
    }, mutate) => mutate({
      variables: {
        description,
      },
    })}
  />
);

Props

PropTypeRequiredDefaultDescription
mutationDocumentNodeYesA GraphQL mutation document parsed into an AST by graphql-tag. Optional for the useMutation Hook since the mutation can be passed in as the first parameter to the Hook. Required for the Mutation component.
variables{ [key: string]: any }{}An object containing all of the variables your mutation needs to execute
update(cache: DataProxy, mutationResult: FetchResult)undefinedA function used to update the cache after a mutation occurs
ignoreResultsbooleanfalseIf true, the returned data property will not update with the mutation result.
optimisticResponseObjectundefinedProvide a mutation response before the result comes back from the server
refetchQueriesArray<string|{ query: DocumentNode, variables?: TVariables}>|((mutationResult: FetchResult) => Array<string|{ query: DocumentNode, variables?: TVariables}>)undefinedAn array or function that allows you to specify which queries you want to refetch after a mutation has occurred. Array values can either be queries (with optional variables) or just the string names of queries to be refeteched.
awaitRefetchQueriesbooleanfalseQueries refetched as part of refetchQueries are handled asynchronously, and are not waited on before the mutation is completed (resolved). Setting this to true will make sure refetched queries are completed before the mutation is considered done. false by default.
onCompleted(data: TData) => voidundefinedA callback executed once your mutation successfully completes
onError(error: ApolloError) => voidundefinedA callback executed in the event of an error.
mutateEventStringonClickIt supports all the DOM even types, and specifies the condition of firing the mutation.

This component accepts all the options base on useMutation hook except context and client

This component accepts all the HTML attributes and event handlers passed in.

2.0.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.13

4 years ago

0.0.12

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.0

5 years ago