Skip to content

Instantly share code, notes, and snippets.

# auth.settings.py
INSTALLED_APPS = [
# ...
'django.contrib.staticfiles', # Required for GraphiQL
'graphene_django',
# refresh tokens are optional
'graphql_jwt.refresh_token.apps.RefreshTokenConfig',
]
# auth.schema.py
import graphene
from graphql_auth.schema import UserQuery, MeQuery
from graphql_auth import mutations
class AuthMutation(graphene.ObjectType):
register = mutations.Register.Field()
GraphQLClient _client = graphQLConfiguration.clientToQuery();
QueryResult result = await _client.mutate(
MutationOptions(
document: addMutation.register('$_email','','$_password'),
),
);
if (result.data["success"]!=null){
print('The user was created successfully!');
}else{
print('There was an error!');
GraphQLConfiguration graphQLConfiguration = GraphQLConfiguration();
QueryMutation addMutation = QueryMutation();
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp( GraphQLProvider(
client: graphQLConfiguration.client,
child: CacheProvider(child: MyApp()),
),);
}
import "package:graphql_flutter/graphql_flutter.dart";
import 'graphQLConf.dart';
import 'queryMutation.dart';
# settings.py
INSTALLED_APPS = [
# ...
"graphql_auth",
]
AUTHENTICATION_BACKENDS = [
# remove this
# "graphql_jwt.backends.JSONWebTokenBackend",
# auth.urls.py
from django.urls import path
from django.views.decorators.csrf import csrf_exempt
from graphene_django.views import GraphQLView
urlpatterns = [
# ...
path("graphql", csrf_exempt(GraphQLView.as_view(graphiql=True))),
]
# auth/settings.py
INSTALLED_APPS = [
# ...
'users'
]
AUTH_USER_MODEL = 'users.CustomUser'
@joaquinacuna
joaquinacuna / models.py
Created November 4, 2020 16:04
User model to flutter example
from django.db import models
# Create your models here.
from django.contrib.auth.models import AbstractUser
class CustomUser(AbstractUser):
EMAIL_FIELD = 'email'
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username']
username= models.CharField(blank=True, max_length=254,)