graphene_server

Last updated:

0 purchases

graphene_server Image
graphene_server Images
Add to Cart

Description:

graphene server

Graphene Server #
A GraphQL inspired server and JSON based Schema. Hecho en 🇵🇷 por Radamés J. Valentín Reyes
New #

Server is now multi-threaded thanks to the compute(https://pub.dev/packages/compute) package I found online.

HTTP POST Request body #
In JSON format
Query #
{
"variables": {
"variable1": 2,
"variable2": "Hello World"
},
"query": "functionName",
"schema": {
"name": "",
"age": "",
"favoriteMovies": {
"name": "",
"realeaseYear": ""
}
}
}
copied to clipboard
Mutation #
{
"variables": {
"variable1": 2,
"variable2": "Hello World"
},
"mutation": "functionName",
"schema": {
"name": "",
"age": "",
"favoriteMovies": {
"name": "",
"realeaseYear": ""
}
}
}
copied to clipboard
Library use examples #
Dart Server #
import 'package:graphene_server/graphene_server.dart';
import 'dart:io';

void main()async{
String message = "Hello World";

await startServer(
server: await HttpServer.bind(InternetAddress.loopbackIPv4, 8080),
query: GrapheneQuery(
resolver: {
"helloWorld": (arguments)async{
return '{"message": "$message"}';
},
},
),
mutations: GrapheneMutation(
resolver: {
"helloWorld": (arguments)async{
message = arguments["newMessage"];
return '{"message": "$message"}';
},
},
),
);
}
copied to clipboard
Dart request example #
Schema support is not yet available. Just pass an empty map/object for now or avoid the schema at all.
Request method is always of type POST.
Request body example below. Request body must always be of type JSON.
{
"variables": {
"newMessage": "New Message"
},
"mutation": "helloWorld",
"schema": {}
}
copied to clipboard
Authentication #
A simple authentication system that stores user accounts as json in a folder called authentication stored in the project's root folder. Here simple auth functions are provided to streamline the creation of servers that require such functionality.
Import authentication functions #
import 'package:graphene_server/auth.dart';
copied to clipboard

Create account

await createAccount(
username: "test",
password: "test",
);
copied to clipboard

Login

print("Access token: ${await login(username: "test", password: "test")}");
copied to clipboard

Logout

await logout(accessToken: "2024YX6M1E7MO1YWTF7C2T5NY41W47RJ66LF9ME0");
copied to clipboard

Get Account

Account? existingAccount = await getAccount(
username: username,
password: password,
);
copied to clipboard

Get Account using Access Token

Account? account = await getAccountUsingAccessToken(
accessToken: accessToken,
);
copied to clipboard

Token is valid

print("Token is valid: ${await tokenIsValid(accessToken: "2JI024ERR6AD171XJKWYYYD7O4522Q533K9WP2T9")}");
copied to clipboard

Update password

await changePassword(
accessToken: "2JI024ERR6AD171XJKWYYYD7O4522Q533K9WP2T9",
newPassword: "coolSafePassword",
);
copied to clipboard

Add role

await addRole(
accessToken: "2JI024ERR6AD171XJKWYYYD7O4522Q533K9WP2T9",
newRole: "Admin",
);
copied to clipboard

Remove role

await removeRole(
accessToken: "2JI024ERR6AD171XJKWYYYD7O4522Q533K9WP2T9",
roleToRemove: "Admin",
);
copied to clipboard

Contribute/donate by tapping on the Pay Pal logo/image #

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.