Skip to content

Instantly share code, notes, and snippets.

View result.dart
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!');
View _LoginpageState.dart
GraphQLConfiguration graphQLConfiguration = GraphQLConfiguration();
QueryMutation addMutation = QueryMutation();
View main.dart
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp( GraphQLProvider(
client: graphQLConfiguration.client,
child: CacheProvider(child: MyApp()),
),);
}
View graphql_flutter.dart
import "package:graphql_flutter/graphql_flutter.dart";
import 'graphQLConf.dart';
import 'queryMutation.dart';
View auth.schema.py
# 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()
View auth.settings.py
# settings.py
INSTALLED_APPS = [
# ...
"graphql_auth",
]
AUTHENTICATION_BACKENDS = [
# remove this
# "graphql_jwt.backends.JSONWebTokenBackend",
View auth.settings.py
# auth.settings.py
INSTALLED_APPS = [
# ...
'django.contrib.staticfiles', # Required for GraphiQL
'graphene_django',
# refresh tokens are optional
'graphql_jwt.refresh_token.apps.RefreshTokenConfig',
]
View auth.urls.py
# 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))),
]
View auth_settings.py
# auth/settings.py
INSTALLED_APPS = [
# ...
'users'
]
AUTH_USER_MODEL = 'users.CustomUser'
@joaquinacuna
joaquinacuna / models.py
Created Nov 4, 2020
User model to flutter example
View models.py
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,)