graphene_server 0.1.0+11 copy "graphene_server: ^0.1.0+11" to clipboard
graphene_server: ^0.1.0+11 copied to clipboard

A GraphQL inspired server and JSON based Schema.

Graphene Server #

A GraphQL inspired server. Hecho en 🇵🇷 por Radamés J. Valentín Reyes

New #

HTTP POST Request body #

In JSON format

Query #

{
  "variables": {
    "variable1": 2,
    "variable2": "Hello World"
  },
  "query": "functionName"
}

Mutation #

{
  "variables": {
    "variable1": 2,
    "variable2": "Hello World"
  },
  "mutation": "functionName"
}

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"}';
        },
      },
    ),
  );
}

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.

Request URL

Always send the requests to your ip:port/graphene

http://localhost:5432/graphene

Request Body

{
  "variables": {
    "newMessage": "New Message"
  },
  "mutation": "helloWorld"
}

Authentication #

A simple authentication system that stores user accounts in the designated authDatabase folder by making use of objective_db. 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';
  • Create account
createAccount(
  authDatabase: authDatabase,
  username: "valentin.radames@gmail.com",
  password: "12345",
);
  • Login
String accessToken = login(
  authDatabase: authDatabase, 
  username: "valentin.radames@gmail.com", 
  password: "12345",
);
  • Logout
logout(
  authDatabase: authDatabase, 
  accessToken: accessToken,
);
  • Token is valid
bool validToken =  tokenIsValid(
  authDatabase: authDatabase, 
  accessToken: accessToken,
);
  • Update password
updatePassword(
  authDatabase: authDatabase, 
  username: "valentin.radames@gmail.com", 
  password: "12345", 
  newPassword: "012345",
);
  • Add role
addRole(
  authDatabase: authDatabase, 
  username: "valentin.radames@gmail.com", 
  role: "Admin",
);
  • Remove role
removeRole(
  authDatabase: authDatabase, 
  username: "valentin.radames@gmail.com", 
  role: "Admin",
);
  • Has Role
bool itHasRole = hasRole(
  authDatabase: authDatabase, 
  accessToken: accessToken,
  role: "Admin",
);
  • Delete Account
deleteAccount(
  authDatabase: authDatabase, 
  username: "valentin.radames@gmail.com",
);
  • Get all stored accounts
List<Map<String,dynamic>> allAccounts = getAllAccounts(authDatabase: authDatabase);
print(allAccounts);

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


1
likes
110
points
4
downloads

Publisher

unverified uploader

Weekly Downloads

A GraphQL inspired server and JSON based Schema.

Documentation

API reference

License

GPL-3.0 (license)

Dependencies

compute, objective_db, power_plant

More

Packages that depend on graphene_server