Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions api/graphql.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// Copyright 2021 Edward McFarlane. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

syntax = "proto3";

package larking.api;

import "google/api/annotations.proto";
import "google/protobuf/any.proto";
import "google/protobuf/descriptor.proto";
import "google/protobuf/struct.proto";

option go_package = "larking.io/api/graphqlpb;graphqlpb";

// Relay GraphQL implementation
// https://relay.dev/docs/guides/graphql-server-specification/
// http://spec.graphql.org/draft/
//
// Cursor implementation
// https://relay.dev/assets/files/connections-932f4f2cdffd79724ac76373deb30dc8.htm#

extend google.protobuf.MethodOptions {
// Adds a method to the GraphQL query root.
Rule graphql = 72222228;
}

extend google.protobuf.FieldOptions {
// Adds relay
optional bool relay_id = 70000;
}

// Rule implements GraphQL bindings.
message Rule {
oneof pattern {
string query = 1;
string mutation = 2;
string subscription = 3;
}

// Args is a mapping of fields.
repeated Arg args = 4;

// Controls the Relay NodeID binding.
string node_id = 5;

// Additional GraphQL bindings for the selector. Nested bindings must
// not contain an `additional_bindings` field themselves (that is,
// the nesting may only be one level deep).
repeated Rule additional_bindings = 6;
}

extend google.protobuf.MessageOptions { Edge edge = 70001; }

message Edge {
string name = 1;
string method = 2;
}

extend google.protobuf.MessageOptions { MessageConnection connection = 70002; }

message Arg {
string name = 1;
string field = 2;
}

// Connection
// https://relay.dev/graphql/connections.htm#
// A field that returns a Connection Type must include forward pagination
// arguments, backward pagination arguments, or both. These pagination arguments
// allow the client to slice the set of edges before it is returned.
//
// Forward Arguments:
// - first takes a non-negative integer.
// - after takes the cursor type as described in the cursor field section.
//
// Backward Arguments:
// - last takes a non-negative integer.
// - before takes the cursor type as described in the cursor field section.
message MessageConnection {
// TODO
string name = 1;
string method = 2;
repeated Arg args = 3;
}

// https://relay.dev/graphql/connections.htm
message PageInfo {
bool has_next_page = 1;
bool has_previous_page = 2;
bytes start_cursor = 3;
bytes end_cursor = 4;
}

message Connection {
repeated google.protobuf.Any edges = 1;
PageInfo page_info = 2;
}

message Request {
string query = 1;
string operation_name = 2;
google.protobuf.Struct variables = 3;
}

message Response {
google.protobuf.Struct data = 1;
repeated Error errors = 2;
}

message SourceLocation {
int32 line = 1;
int32 column = 2;
}

message Error {
string message = 1;
repeated SourceLocation locations = 2;
repeated string path = 3;
}

service GraphQL {
rpc Query(Request) returns (Response) {
option (google.api.http) = {
post : "/graphql"
additional_bindings {get : "/graphql"}
};
}
// TODO: Subscriptions
}

// message GetRelayNodeRequest { string id = 1; }
//
//// Relay service is a client required service for GraphQL options.
// service Relay {
// // GetRelayNode exposes ID! querying capabilities to the GraphQL service.
// rpc GetRelayNode(GetRelayNodeRequest) returns (google.protobuf.Any);
// }
Loading