Strawberry with social_django

170 views Asked by At

How can I use social_django with strawberry graphql? With graphene, I inherited my strawberry.type from SocialAuthJWT I used in grapgene like this.

class SocialAuth(graphql_social_auth.SocialAuthJWT):
    user = graphene.Field(UserType)

    @classmethod
    def resolve(cls, root, info, social, **kwargs):
        social.user.is_verified = True
        social.user.save()
        token = get_token(social.user)
        return cls(user=social.user, token=token)

I'd like to log in with google.

1

There are 1 answers

0
Shritesh99 On

Made a library for this inspired by nrbnlulu/strawberry-django-auth

Check it out here

Build your schema like this

@strawberry.type
class Mutation:
    social_auth = mutations.SocialAuth.field

schema = strawberry.Schema(query=Query, mutation=Mutation)

Call it like this:

 mutation SocialAuth($provider: String!, $accessToken: String!){
                socialAuth(provider: $provider, accessToken: $accessToken){
                    uid
                    extraData
                    errors
                    success
                    refreshToken {
                        created
                        isExpired
                        expiresAt
                        token
                        revoked
                    }
                    token {
                        token
                        payload {
                            exp
                            origIat
                        }
                    }
                    user {
                        archived
                        dateJoined
                        firstName
                        isActive
                        id
                        isStaff
                        isSuperuser
                        lastLogin
                        lastName
                        logentrySet {
                            pk
                        }
                        status {
                            archived
                            verified
                        }
                        verified
                    }
                  }
                }

You can also extend the SocialAuthMixin to customize the behavior of your SocialAuth:)