joselfonseca / lighthouse-graphql-passport-auth

Add GraphQL mutations to get tokens from passport for https://lighthouse-php.com/
https://lighthouse-php-auth.com/
MIT License
228 stars 56 forks source link

Support for Eloquent relationships in Register resolver? #143

Closed tjbp closed 3 years ago

tjbp commented 3 years ago

Would it be considered within the scope of this package to support Eloquent relationships inside the Register mutation?

I ask primarily because the Register mutation is likely to be the most widely-used method for user record creation in a project, so being able to populate relationships in a single query would be useful. As an example, if I was to add the groups field below to the Register input type:

input RegisterInput {
    name: String! @rules(apply: ["required", "string"])
    email: String! @rules(apply: ["required", "email"])
    password: String! @rules(apply: ["required", "confirmed", "min:8"])
    password_confirmation: String!
    phone_number: String! @rules(apply: ["required", "string"])
    groups: BelongsToManyGroups
}

input BelongsToManyGroups {
    connect: [ID!]
}

I would expect the above to behave like Lighthouse and detect that groups is a relationship on the Auth model and create a connection between the two records. Currently it seems the Register resolver is only compatible with standard mass-assignable attributes.

I appreciate that a custom resolver could be created for this purpose, or shall I create a pull request (if mimicking Lighthouse is desirable)?

joselfonseca commented 3 years ago

This is a good use case for a custom resolver. If you still want to use the regular relationship handling provided by lighthouse you may want to use a directive instead on top or other directives like @create. I don't think everyone needs this so it does not fall under the scope of the package. Thank you for the issue and let me know if there is anything else i can help with.