Calling auto-generated queries and mutations with neo4j-graphql-js

234 Views Asked by At

After a suggestion from another question I had, with version 1.0.2 of neo4j-graphql-js, relationships are supported now with the auto-generated schemas.

What I had been doing up to this point, due to a kind of complex form was import my graphql queries in my React component like this:

import { CREATE_NEW_RECIPE, CREATE_RECIPE_INGREDIENTS } from '../../graphql';

I would use the react-apollo 'compose' to export my react component like so:

const CreateRecipeWithMutations = compose(
    graphql(CREATE_NEW_RECIPE, { name: 'CreateRecipe' }),
    graphql(CREATE_RECIPE_INGREDIENTS, { name: 'CreateIngredientRelation' }))(CreateRecipe)

export default CreateRecipeWithMutations

And then I would call these graphql mutations/queries like this:

        const recipe = await this.props.CreateRecipe({
            variables: {
                name: this.state.name,
                time: this.state.time, true,
                instructions: this.state.instructions
            }
        })

And this concept was working as a way to use these graphql queries without using graphql-tag when I wanted to make certain mutations only run depending on the results of earlier mutations.

Now neo4j-graphql-js is generating a lot of the hand-crafted items I wrote and that's great and I would like to use them. I see them in the GraphQL Playground and I can run them there with the proper parameters. How can I access them in my react component without it knowing about them ahead of time? I know if I was using graphql-tag I could define my object and pass in a query parameter like the do in this file: https://github.com/grand-stack/grand-stack-starter/blob/master/ui/src/UserList.js

However I don't want to use the queries like that and want to call them without wrapping them in tags. There might be a way to use the tag without it being in the render return statements but I haven't been able to get that to work yet. If so I wouldn't object to using it that way.

Any help would be appreciated.

0

There are 0 best solutions below