• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created about 3 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Maintain the source code for GraphQL related tools.

graphql-tools

Maintain the source code for GraphQL related tools.

Build master GitHub Last Commit License codecov

Every GraphQL service defines a set of types that completely describe the set of possible data you can query on that service. Then, when queries come in, they are validated and executed against that schema. GraphQL schemas for a service are now most often specified using whatโ€™s known as the GraphQL SDL (schema definition language), also sometimes referred to as just GraphQL schema language. Ballerina GraphQL tooling will make it easy for you to start the development of a client in Ballerina for a given GraphQL SDL and a GraphQL document configured in a GraphQL config file by generating Ballerina client skeletons. You can generate a single client in Ballerina for multiple GraphQL documents for a given GraphQL SDL. It also enables you to generate multiple Ballerina modules for multiple GraphQL projects to work with different GraphQL APIs. In addition, the GraphQL tooling supports generating the GraphQL schema specified by Schema Definition Language for a given Ballerina GraphQL service. The user will be able to generate the schema and export it to a specific directory for a selected set of services in the given bal file. Also, the GraphQL tooling makes it easy to start the development of a service in Ballerina for a given GraphQL schema by generating Ballerina service skeletons.

The Ballerina GraphQL tooling support provides the following capabilities.

  1. Generating a Ballerina client from a given GraphQL config file configured with a GraphQL schema specified by Schema Definition Language and a GraphQL document.

  2. Generating a Ballerina client from a given GraphQL config file configured with a GraphQL schema specified by Schema Definition Language and multiple GraphQL documents.

  3. Generating multiple Ballerina modules from a given GraphQL config file configured with multiple GraphQL projects. Each project will generate a separate Ballerina module. This enables you to work with multiple GraphQL APIs by configuring each GraphQL API under a separate project.

  4. Generate the GraphQL schema specified by Schema Definition Language for a given Ballerina GraphQL service(s).

  5. Generate a Ballerina service from a given GraphQL schema specified by Schema Definition Language.

Command for Ballerina GraphQL client generation

The graphql command in Ballerina can be used for GraphQL to Ballerina code generation and Ballerina to GraphQL schema generation. The command usages for GraphQL to Ballerina code generation are as follows.

bal graphql [-i | --input] <graphql-configuration-file-path> [-o | --output] <output-location>

The command line arguments below can be used with the command for each particular purpose as described below.

Argument Description
-i, --input The input parameter specifies the path of the GraphQL config file (e.g., graphql.config.yaml) configured with GraphQL schemas specified by Schema Definition Language and GraphQL documents. This parameter is mandatory.
-o, --output The output parameter specifies the path of the output location of the generated files. This parameter is optional. If this parameter is not specified, the Ballerina files will be generated at the same location from which the GraphQL command is executed.

Command for GraphQL schema generation

The graphql command for GraphQL schema generation and the usages are as follows.

bal graphql [-i | --input] <graphql-service-file-path> [-o | --output] <output-location> [-s | --service] <service-base-path>
Argument Description
-i, --input The input parameter specifies the path of the Ballerina GraphQL service file (e.g., service.bal). This parameter is mandatory. This parameter is mandatory.
-o, --output The output parameter specifies the path of the output location of the generated GraphQL schema files. This parameter is optional. If this parameter is not specified, the schema files will be generated at the same location from which the GraphQL command is executed.
-s, --service The service parameter specifies the base path of the Ballerina GraphQL service which the schema is needed to be generated. This parameter is optional. If this parameter is not specified, the schema files will be generated for all the Ballerina GraphQL services declared in the input file.

Command for Ballerina GraphQL service generation

The graphql command for Ballerina Graphql service generation and the usages are as follows.

bal graphql [-i | --input] <graphql-schema-file-path> [-o | --ouput] <output-location> [-m | --mode] <operation-mode> [-r | --use-records-for-objects]
Argument Description
-i, --input The input parameter specifies the path of the GraphQL schema file (e.g., schema.graphql). This parameter is mandatory.
-o, --output The output parameter specifies the path of the output location of the generated Ballerina GraphQL service files. This parameter is optional. If this parameter is not specified, the service files will be generated at the same location from which the GraphQL command is executed.
-m, --mode The mode parameter specifies the operation mode. It can be client, schema, or service. They represent Ballerina GraphQL client generation, GraphQL schema generation, and Ballerina GraphQL service generation respectively. The mode flag is optional. If the mode flag is not specified, the graphql tool will infer the mode from the input file extension.
-r, --use-records-for-objects The use-records-for-objects flag makes the GraphQL tool use record types for GraphQL object types whenever possible in Ballerina GraphQL service generation. This flag is optional and it can only be used with the GraphQL service generation.

Generate a Ballerina client from a GraphQL config file configured with a GraphQL schema (SDL) and GraphQL document

Create a GraphQL config file (graphql.config.yaml) with the following configuration.

schema: <File path to the GraphQL schema or the web URL of the GraphQL schema>
documents:
    - <File path to the GraphQL document with the GraphQL queries & mutations>

The client generated from the GraphQL config file can be used in your applications to call the queries/mutations in the GraphQL document against the GraphQL API corresponding to the GraphQL schema defined in the GraphQL config file.

If you want to generate the Ballerina client for a given GraphQL document you can use the following command.

bal graphql [-i | --input] <graphql-configuration-file-path> [-o | --output] <output-location>

This will generate a Ballerina client with remote operations corresponding to each GraphQL query/mutation in the GraphQL document (.graphql document).

For example,

bal graphql -i graphql.config.yaml

This will generate a Ballerina client stub (client.bal), a util file (utils.bal) for the relevant utils methods related to the client stub, a schema file (types.bal) for the configured GraphQL schema, and a config file (config_types.bal) for all the Ballerina data types related to connector configuration. The above command can be run from anywhere on the execution path. It is not mandatory to run it from within a Ballerina project.

NOTE: If the GraphQL API contains an authentication mechanism, make sure to add the extensions section in the GraphQL config file with the relevant tokens and headers. In this scenario itโ€™s mandatory to configure the schema section with the web URL of the GraphQL schema.

schema: <The web URL of the GraphQL schema.>
documents:
     - <File path to the GraphQL document with the GraphQL queries & mutations>
extensions:
     endpoints:
         default:
              headers: { "<Authorization>": "<Bearer token>", "<API_Header_Key1>": "<API_Header_Value1>", "<API_Header_Key2>": "<API_Header_Value2>" }

Generate a Ballerina client from a GraphQL config file configured with a GraphQL schema (SDL) and multiple GraphQL documents

Create a GraphQL config file (graphql.config.yaml) with the following configuration.

schema: <File path to the GraphQL schema or the web URL of the GraphQL schema>
documents:
    - <File path to the GraphQL document with the GraphQL queries & mutations>
    - <File path to the GraphQL document with the GraphQL queries & mutations>
    - <File path to the GraphQL document with the GraphQL queries & mutations>
    - <Add more documents based on your requirement โ€ฆ >

The client generated from the GraphQL config file can be used in your applications to call the queries/mutations in each GraphQL document against the GraphQL API corresponding to the GraphQL schema defined in the GraphQL config file.

If you want to generate a single Ballerina client for a given set of GraphQL documents you can use the following command.

bal graphql [-i | --input] <graphql-configuration-file-path> [-o | --output] <output-location> 

This will generate a Ballerina client to represent all the GraphQL documents with remote operations corresponding to each GraphQL query/mutation in the GraphQL document (.graphql document).

For example,

bal graphql -i graphql.config.yaml

This will generate a Ballerina client stub (client.bal) with all the remote operations, a util file (utils.bal) for the relevant utils methods related to the client stub, a schema file (types.bal) for the configured GraphQL schema, and a config file (config_types.bal) for all the Ballerina data types related to connector configuration. The above command can be run from anywhere on the execution path. It is not mandatory to run it from within a Ballerina project.

Generate multiple Ballerina modules from a GraphQL config file configured with multiple GraphQL projects

Create a GraphQL config file (graphql.config.yaml) with the following configuration.

projects:
    <project1_name>:
        schema: <File path to the GraphQL schema or the web URL of the GraphQL schema>
        documents:
            - <File path to the GraphQL document with the GraphQL queries & mutations>
            - <File path to the GraphQL document with the GraphQL queries & mutations>
            - <Add more documents based on your requirement โ€ฆ >
    <project2_name>:
        schema: <File path to the GraphQL schema or the web URL of the GraphQL schema>
        documents:
            - <File path to the GraphQL document with the GraphQL queries & mutations>
            - <File path to the GraphQL document with the GraphQL queries & mutations>
            - <Add more documents based on your requirement โ€ฆ >
    <project3_name>:
        schema: <File path to the GraphQL schema or the web URL of the GraphQL schema>
        documents:
            - <File path to the GraphQL document with the GraphQL queries & mutations>
            - <File path to the GraphQL document with the GraphQL queries & mutations>
            - <Add more documents based on your requirement โ€ฆ >
    <Add more projects based on your requirement โ€ฆ >

This enables you to work with multiple GraphQL APIs. Each GraphQL API should be defined under a separate project in the GraphQL config file. The client generated under a separate Ballerina module related to each project from the GraphQL config file can be used in your applications to call the queries/mutations in each GraphQL document against the GraphQL API corresponding to the GraphQL schema defined under each project in the GraphQL config file.

If you want to generate multiple Ballerina modules for a given set of GraphQL projects you can use the following command.

bal graphql [-i | --input] <graphql-configuration-file-path> [-o | --output] <output-location>

This will generate a separate Ballerina module for each GraphQL project with clients corresponding to each GraphQL document configured under each GraphQL project.

For example,

bal graphql -i graphql.config.yaml

This will generate a Ballerina module (project_name) corresponding to each GraphQL project. Each project will generate a Ballerina client stub (client.bal) corresponding to each GraphQL document configured under the relevant GraphQL project, an util file (utils.bal) for the relevant utils methods related to the client stubs, a schema file (types.bal) for the configured GraphQL schema under the relevant GraphQL project, and a config file (config_types.bal) for all the Ballerina data types related to connector configuration. The above command can be run from anywhere on the execution path. It is not mandatory to run it from within a Ballerina project.

Building from the Source

Setting Up the Prerequisites

  1. Download and install Java SE Development Kit (JDK) version 17. You can install either OpenJDK or Oracle.

    Note: Set the JAVA_HOME environment variable to the path name of the directory into which you installed JDK.

  2. Export GitHub Personal access token with read package permissions as follows,

    export packageUser=<Username>
    export packagePAT=<Personal access token>
    

Building the Source

Execute the commands below to build from the source.

  1. To build the library:

     ./gradlew clean build
    
  2. To run the integration tests:

     ./gradlew clean test
    
  3. To build the module without the tests:

     ./gradlew clean build -x test
    

Contributing to Ballerina

As an open-source project, Ballerina welcomes contributions from the community.

For more information, go to the contribution guidelines.

Code of Conduct

All contributors are encouraged to read the Ballerina Code of Conduct.

Useful Links

More Repositories

1

ballerina-lang

The Ballerina Programming Language
Ballerina
3,286
star
2

lsp4intellij

This language client library provides language server protocol support for IntelliJ IDEA and other Jetbrains IDEs.
Java
413
star
3

ballerina-spec

Ballerina Language and Platform Specifications
HTML
171
star
4

ballerina-dev-website

Dev version of the ballerina.io website
HTML
163
star
5

module-ballerina-graphql

The Ballerina GraphQL module is part of the Ballerina Standard Library. It is a spec-compliant, production-ready GraphQL implementation for writing GraphQL APIs in Ballerina.
Ballerina
144
star
6

nballerina

Ballerina compiler that generates native executables.
Ballerina
142
star
7

ballerina-library

The Ballerina Library
Ballerina
137
star
8

module-ballerina-jwt

Ballerina JWT module.
Ballerina
130
star
9

openapi-tools

Ballerina OpenApi-Tool
Java
129
star
10

module-ballerina-grpc

Ballerina gRPC Module
Ballerina
128
star
11

ballerina-release

Ballerina release scripts
Python
126
star
12

openapi-connectors

Generate Ballerina connector with OpenAPI definition
Ballerina
126
star
13

module-ballerina-http

Ballerina HTTP Module
Java
124
star
14

module-ballerinax-nats

Ballerina NATS Module.
Ballerina
124
star
15

ballerina-platform.github.io

ballerina-platform.github.io - Github pages based ballerina.io website
HTML
124
star
16

ballerina-action

Dockerfile
124
star
17

module-ballerina-io

Ballerina io Module
Ballerina
123
star
18

module-ballerina-tcp

Ballerina socket module
Java
122
star
19

module-ballerina-oauth2

Ballerina OAuth2 Module
Ballerina
122
star
20

module-ballerina-websocket

Ballerina WebSocket Module
Java
121
star
21

module-ballerina-websub

Ballerina Websub module.
Ballerina
120
star
22

module-ballerina-mime

Ballerina MIME Module
Java
119
star
23

plugin-intellij

Ballerina extension for IntelliJ IDEA.
Java
119
star
24

module-ballerinax-mysql

Ballerina mysql Module
Ballerina
119
star
25

module-ballerina-auth

Ballerina Auth Module
Java
119
star
26

module-ballerina-sql

Ballerina SQL Module
Java
119
star
27

module-ballerina-email

Ballerina module to send and receive emails
Java
119
star
28

module-ballerinax-kafka

Ballerina Kafka Module.
Ballerina
119
star
29

module-ballerina-udp

Ballerina UDP module enables transport layer communication over UDP protocol.
Java
118
star
30

module-ballerinax-java.jdbc

Ballerina JDBC Module
Ballerina
118
star
31

module-ballerina-cache

Ballerina cache Module
Ballerina
118
star
32

module-ballerina-log

Ballerina log Module
Ballerina
118
star
33

module-ballerina-c2c

Ballerina Code2Cloud implementation
Java
118
star
34

module-ballerinax-slack

Ballerina slack module
Ballerina
118
star
35

module-ballerinax-azure-cosmosdb

Ballerina
118
star
36

plugin-vscode-compiler-toolkit

Compiler tools for Ballerina developers
TypeScript
118
star
37

ballerina-dev-tools

Ballerina Developer Tooling
Java
118
star
38

module-ballerinax-stan

Ballerina NATS Streaming Module.
Java
117
star
39

module-ballerina-crypto

Ballerina crypto Module
Ballerina
117
star
40

module-ballerina-websubhub

This modules includes a bunch of APIs to facilitate writing different WebSub Hub implementations
Ballerina
116
star
41

module-ballerinax-googleapis.calendar

Connector repository for Google Calendar API.
Ballerina
116
star
42

module-ballerina-xmldata

Ballerina xml utils Module
Ballerina
116
star
43

module-ballerinax-postgresql

Ballerina PostgreSQL DB module
Ballerina
116
star
44

module-ballerinax-java.jms

Ballerina
116
star
45

module-ballerina-file

Ballerina File Module
Ballerina
116
star
46

module-ballerinax-azure-service-bus

Ballerina
116
star
47

module-ballerinax-aws.dynamodb

This is to keep the Amazon DynamoDB connector for Ballerina.
Ballerina
116
star
48

module-ballerinax-aws.s3

Ballerina
116
star
49

module-ballerina-task

Ballerina task Module
Java
116
star
50

module-ballerina-time

Ballerina time Module
Ballerina
116
star
51

module-ballerinax-azure.functions

The implementation of Azure Functions compiler extension for Ballerina.
Java
116
star
52

module-ballerinax-datamapper

A compiler extension to extract abstract representation of Ballerina connector actions and their associated types
Java
116
star
53

module-ballerina-uuid

Ballerina UUID Module
Ballerina
116
star
54

module-ballerinax-netsuite

The Ballerina connector to perform operations on Netsuite integrate cloud system.
Ballerina
116
star
55

module-ballerinax-twitter

This repo is to keep Ballerina Twitter connector implementation for Ballerina
Ballerina
116
star
56

ballerina-update-tool

Ballerina Update Tool implementation to manage Ballerina versions
Java
116
star
57

module-ballerinax-ai.agent

Ballerina ReAct type Agent module using Large language models (LLMs)
Ballerina
115
star
58

module-ballerina-os

Ballerina system Module
Java
115
star
59

module-ballerinax-jaeger

Ballerina Jaeger Observability Extension Module
Java
115
star
60

module-ballerinax-aws.sqs

Ballerina
115
star
61

module-ballerinax-mssql

Ballerina MSSQL DB module
Ballerina
115
star
62

module-ballerinax-aws.lambda

Java
115
star
63

module-ballerina-serdes

This is the Ballerina SerDes package, which is a part of the Ballerina Language Standard Library
Java
115
star
64

module-ballerinax-oracledb

Oracle Database Connector for Ballerina
Ballerina
115
star
65

module-ballerina-xslt

Ballerina xslt module
Java
115
star
66

module-ballerina-url

Ballerina encoding module.
Ballerina
115
star
67

module-ballerinax-rabbitmq

Ballerina RabbitMQ Module.
Ballerina
115
star
68

module-ballerinax-prometheus

Ballerina Prometheus Observability Extension Module
Java
115
star
69

module-ballerinai-transaction

Ballerina internal module of transaction implementation
Ballerina
115
star
70

module-ballerinax-mysql.driver

Ballerina Azure MySQL Module
Ballerina
115
star
71

module-ballerinax-azure-storage-service

Ballerina
115
star
72

module-ballerina-jballerina.java.arrays

Ballerina Java Array Module
Ballerina
114
star
73

module-ballerina-constraint

Ballerina Constraint Module
Ballerina
114
star
74

module-ballerinax-choreo

Ballerina Choreo Observability Extension Module
Java
114
star
75

ballerina-performance-cloud

Ballerina Performance Tests in Cloud
Shell
114
star
76

module-ballerinax-azure.eventhub

Azure Eventhub connector
Ballerina
114
star
77

module-ballerina-regex

Ballerina Regex Module
Ballerina
114
star
78

plugin-gradle

Ballerina Gradle plugin
Groovy
114
star
79

module-ballerinax-mssql.driver

Ballerina MSSQL DB Driver
Ballerina
114
star
80

module-ballerina-random

Ballerina Random Library
Ballerina
114
star
81

module-ballerinax-health.fhir.templates

FHIR Ballerina templates
Ballerina
114
star
82

module-ballerinax-persist.sql

SQL database support of Ballerina Persist
Ballerina
114
star
83

module-ballerinax-microsoft.onedrive

The Ballerina connector to perform operations on the files, which is stored on OneDrive
Ballerina
114
star
84

ballerina-custom-jre

Generates platform-specific custom Java runtime images to be bundled with Ballerina platform distributions, which contains only the required modules for Ballerina runtime.
114
star
85

asyncapi-tools

This repository is the code base for the ballerina async-api tool
Java
114
star
86

persist-tools

Ballerina persist tools
Ballerina
113
star
87

module-ballerinax-cdata.connect

Manage Ballerina CData connector modules centrally.
Java
113
star
88

module-ballerina-persist

Ballerina Persist module
Java
113
star
89

module-ballerinax-peoplehr

Ballerina connector for People HR
Ballerina
113
star
90

module-ballerinax-aws.ses

The Ballerina connector to perform operations on Amazon Simple Email Service(Amazon SES).
Ballerina
113
star
91

module-ballerinax-googleapis.people

Repository for Google People API Connector
Ballerina
113
star
92

module-ballerinax-microsoft.teams

The Ballerina Microsoft Teams Connector for teamwork and intelligent communications.
Ballerina
113
star
93

module-ballerinax-googleapis.drive

Repository for Google Drive module.
Ballerina
113
star
94

module-ballerinax-microsoft.excel

The Ballerina connector to perform operations on Excel workbooks stored in Microsoft OneDrive.
Ballerina
113
star
95

asyncapi-triggers

This repo will contain the trigger source code generated through ballerina async api tool
Ballerina
113
star
96

module-ballerinax-aws.simpledb

This is to keep the Amazon SimpleDB connector for Ballerina.
Ballerina
112
star
97

module-ballerinax-aws.sns

This repo is to keep the newly written Amazon SNS connector for Ballerina.
Ballerina
112
star
98

module-ballerina-toml

Ballerina TOML Parser
Ballerina
112
star
99

edi-tools

This library provides the functionality required to process EDI files and implement EDI integrations.
Ballerina
112
star
100

module-ballerinax-health.fhir.r4

FHIR R4 Ballerina modules
Ballerina
112
star