graphene_server 0.0.7+7 copy "graphene_server: ^0.0.7+7" to clipboard
graphene_server: ^0.0.7+7 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 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';
  • Create account
await createAccount(
  username: "test", 
  password: "test",
);
  • Login
print("Access token: ${await login(username: "test", password: "test")}");
  • Logout
await logout(accessToken: "2024YX6M1E7MO1YWTF7C2T5NY41W47RJ66LF9ME0");
  • Get Account
Account? existingAccount = await getAccount(
  username: username, 
  password: password,
);
  • Get Account using Access Token
Account? account = await getAccountUsingAccessToken(
  accessToken: accessToken,
);
  • Token is valid
print("Token is valid: ${await tokenIsValid(accessToken: "2JI024ERR6AD171XJKWYYYD7O4522Q533K9WP2T9")}");
  • Update password
await changePassword(
  accessToken: "2JI024ERR6AD171XJKWYYYD7O4522Q533K9WP2T9", 
  newPassword: "coolSafePassword",
);
  • Add role
await addRole(
  accessToken: "2JI024ERR6AD171XJKWYYYD7O4522Q533K9WP2T9", 
  newRole: "Admin",
);
  • Remove role
await removeRole(
  accessToken: "2JI024ERR6AD171XJKWYYYD7O4522Q533K9WP2T9", 
  roleToRemove: "Admin",
);

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


1
likes
110
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

A GraphQL inspired server and JSON based Schema.

Documentation

API reference

License

GPL-3.0 (license)

Dependencies

compute, power_plant

More

Packages that depend on graphene_server