zngly / wp-graphql-acf-mutations

WP GraphQl ACF Mutations Plugin
Other
7 stars 1 forks source link

feat: Input Types #1

Closed zngly-vlad closed 2 years ago

zngly-vlad commented 2 years ago

This issue is regarding improvements to the graphql-acf-mutations custom implementation.

Given:

const SocialLinksQuery = graphql`
    fragment SocialLinks_Fragment on ZnglyInfo {
        znglyInfo {
            socialLinks {
                facebookLink
                instagramLink
                linkedinLink
                pinterestLink
                vimeoLink
                twitterLink
                youtubeLink
            }
            socialToggle
        }
    }
`;

const SocialLinksMutation = graphql`
mutation SocialLinks_Mutation(
    $id: ID!,
    $socialToggle: [String],
    $facebookLink: String,
    $instagramLink: String,
    $linkedinLink: String,
    $pinterestLink: String,
    $vimeoLink: String,
    $twitterLink: String,
    $youtubeLink: String,
    )
    {
    updateZnglyInfo(
        input: {
            id: $id,
            socialToggle: $socialToggle,
            socialLinks: {facebookLink: $facebookLink, instagramLink: $instagramLink, linkedinLink: $linkedinLink, pinterestLink: $pinterestLink, twitterLink: $twitterLink, vimeoLink: $vimeoLink, youtubeLink: $youtubeLink}
        } ) {
        znglyInfo {
            znglyInfo {
                socialLinks {
                    facebookLink
                    instagramLink
                    linkedinLink
                    pinterestLink
                    vimeoLink
                    twitterLink
                    youtubeLink
                }
                socialToggle
            }
        }
    }
}
`;

The Acf fields should be grouped into an Input Type.

const SocialLinksMutation = graphql`
    mutation SocialLinks_Mutation($id: ID!, $ZnglyInfoAcfInput: [String]) {
        updateZnglyInfo(input: { id: $id, acf: $ZnglyInfoAcfInput }) {
            znglyInfo {
                ...SocialLinks_Fragment
            }
        }
    }
`;

This would

input: {
    id,
    title,
    acf: {
        acf_field_here,
        etc...
    }
}