• /
  • EnglishEspañolFrançais日本語한국어Português
  • Se connecterDémarrer

Cette traduction automatique est fournie pour votre commodité.

En cas d'incohérence entre la version anglaise et la version traduite, la version anglaise prévaudra. Veuillez visiter cette page pour plus d'informations.

Créer un problème

NerdGraphMutation

Un composant de mutation générique NerdGraph qui vous permet de muter n'importe quoi de NerdGraph.

Usage

import { NerdGraphMutation } from 'nr1'

Exemples

Faire une mutation

NerdGraphMutation.mutate({
mutation: ngql`
mutation($guid: EntityGuid!) {
taggingAddTagsToEntity(
guid: $guid
tags: { key: "team", values: ["ui"] }
) {
errors {
message
}
}
}
`,
variables: {
guid: 'XXXXXXXXXXX',
},
});

Effectuer une mutation et une nouvelle récupération de la requête

function render() {
const mutation = ngql`
mutation($guid: EntityGuid!) {
taggingAddTagsToEntity(guid: $guid, tags: $tags) {
errors {
message
}
}
}
`;
const variables = {
guid: 'XXXXXXXXXXX',
tags: { key: 'team', values: ['ui'] },
};
// NOTE: Sometimes mutations take awhile so doing a refetch immediatly after a mutate
// doesn't show any change.
return (
<NerdGraphQuery query={query} variables={variables}>
{({ data, refetch }) => (
<>
<RenderData data={data} />
<Button
onClick={() =>
NerdGraphMutation.mutate({
mutation,
variables,
}).then(refetch)
}
>
Mutate
</Button>
</>
)}
</NerdGraphQuery>
);
}

Accessoires

children

OBLIGATOIRE
fonction

Rendre la fonction prop comme des enfants.

function (
mutate: function,

Function to trigger a mutation from your UI.

mutationResult: MutationResult

Results of the mutation.

) => React.ReactNode

mutation

OBLIGATOIRE
chaîne|objet

Mutation GraphQL, soit sous forme de chaîne, soit sous forme de document GraphQL analysé dans un AST par graphql-tag.

import { ngql } from 'nr1';
const mutation = ngql`
mutation($guid: EntityGuid!) {
taggingAddTagsToEntity(guid: $guid, tags: $tags) {
errors {
message
}
}
}
`;

unsafeExperimentalNamespaces

string[]

Liste contenant l'espace de nommage expérimental non sécurisé que votre requête choisit d'utiliser.

variables

objet

Objet contenant toutes les variables dont votre mutation a besoin pour s'exécuter.

Méthodes

NerdGraphMutation.mutate

function (
props: Object

Object containing the mutation options. Any NerdGraphMutation prop is a valid option except children.

) => PromiseQueryResult

Définitions de types

PromiseQueryResult

{
error: ApolloClient.ApolloError,

Runtime error with graphQLErrors and networkError properties.

data: Object,

Object containing the result of your query.

fetchMore: function|null,

If not null, fetchMore allows you to load more results for your query. New data is merged with previous data.

refetch: function,

Refetch the query.

}

MutationResult

{
loading: boolean,

Indicates that the request is in flight.

error: ApolloClient.ApolloError,

Runtime error with graphQLErrors and networkError properties.

data: Object,

Object containing the result of your mutation.

}
Droits d'auteur © 2025 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.