How to reuse a mutation?

I need to perform the same mutation but in different components and on different pages. How can I reuse a single mutation so I’m not repeating my code?

Maybe try to put the mutation in it’s own file and export it.

import { gql, graphql } from 'react-apollo';

class NewEntry extends Component { ... }

const submitRepository = gql`
  mutation submitRepository {
    submitRepository(repoFullName: "apollographql/apollo-client") {
      createdAt
    }
  }
`;

export const withSubmitRepository = graphql(submitRepository);

Then in component file:

import React, { Component } from 'react';
import { withSubmitRepository } from '../graphql/mutations';

class NewEntry extends Component { ... }

export default withSubmitRepository(NewEntry);