Skip to content

Instantly share code, notes, and snippets.

@danstarns
Last active April 11, 2021 09:33
Show Gist options
  • Save danstarns/4ff18b00bb947c3d186603a65a7752d5 to your computer and use it in GitHub Desktop.
Save danstarns/4ff18b00bb947c3d186603a65a7752d5 to your computer and use it in GitHub Desktop.
mutations-comparison

Mutations Comparison

Comparison of mutations between neo4j-graphql-js and @neo4j/graphql.

Schema

Image from Gyazo

type Product {
    id: ID
    name: String
    photos: [Photo] @relationship(type: "HAS_PHOTO", direction: OUT)
}

type Photo {
    id: ID
    url: String
    name: String
    color: Color @relationship(type: "HAS_COLOR", direction: OUT)
}

type Color {
    name: String
}

@neo4j/graphql

mutation {
    createProducts(
        input: [
            {
                id: "pringles_product_id"
                name: "Pringles"
                photos: {
                    create: [
                        {
                            id: "green_photo_id"
                            url: "green_photo_url.com"
                            name: "Green photo"
                            color: { connect: { where: { name: "Green" } } } # existing color
                        }
                        {
                            id: "red_photo_id"
                            url: "outdoor_photo_url.com"
                            name: "Red photo"
                            color: { connect: { where: { name: "Red" } } } # existing color
                        }
                    ]
                }
            }
        ]
    ) {
        id
    }
}

neo4j-graphql-js

mutation {
    product: CreateProduct(id: "pringles_product_id", name: "Pringles") {
        id
    }
    greenPhoto: CreatePhoto(
        id: "green_photo_id"
        url: "green_photo_url.com"
        name: "Green Photo"
    ) {
        id
    }
    connectedProductGreenPhoto: MergeProductPhotos(
        from: { id: "pringles_product_id" }
        to: { id: "green_photo_id" }
    ) {
        to {
            id
        }
    }
    connectGreenPhotoColor: MergePhotoColor(
        from: { id: "green_photo_id" }
        to: { name: "Green" }
    ) {
        to {
            name
        }
    }

    redPhoto: CreatePhoto(
        id: "red_photo_id"
        url: "red_photo_url.com"
        name: "Red Photo"
    ) {
        id
    }
    connectedProductRedPhoto: MergeProductPhotos(
        from: { id: "pringles_product_id" }
        to: { id: "red_photo_id" }
    ) {
        to {
            id
        }
    }
    connectRedPhotoColor: MergePhotoColor(
        from: { id: "red_photo_id" }
        to: { name: "Red" }
    ) {
        to {
            name
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment