Git Product home page Git Product logo

apollo-and-ballerina's Introduction

Apollo and Ballerina GraphQL Comparison

This repository contains source code for a simple social media service exposed via a GraphQL API. Following is the GraphQL schema for the GraphQL service.

type Query {
  "Returns the list of users."
  users: [User!]!
  "Returns the user with the given ID."
  user(
    "ID of the user"
    id: String!
  ): User!
  "Returns the list of posts from a user."
  posts(
    "ID of the user"
    id: String
  ): [Post!]!
}

"Represents the User type in the GraphQL schema."
type User {
  "The `id` of the User"
  id: String!
  "The `name` of the User"
  name: String!
  "The `age` of the User"
  age: Int!
  "The `posts` posted by the User"
  posts: [Post!]!
}

"Represents the Post type in the GraphQL schema."
type Post {
  "The `id` of the Post"
  id: String!
  "The `title` of the Post"
  title: String!
  "The `content` of the Post"
  content: String!
  "The `author` of the Post"
  author: User!
}

type Mutation {
  "Creates a new user."
  createUser(
    "User to be created"
    user: NewUser!
  ): User!
  "Deletes a user. Only the user can delete their own account. Will return an authentication/authorization error if the user cannot be authenticated/authorized."
  deleteUser(
    "ID of the user"
    id: String!
  ): User!
  "Creates a new post. Can return authentication error if the user is not authenticated."
  createPost(
    "Post to be created"
    newPost: NewPost!
  ): Post!
  "Deletes a post with the given ID. Can return authentication/authorization errors if the user cannot be authenticated/authorized."
  deletePost(
    "ID of the post"
    id: String!
  ): Post!
}

"Represents the NewUser type in the GraphQL schema."
input NewUser {
  "The `name` of the User"
  name: String!
  "The `age` of the User"
  age: Int!
}

"Represents the NewPost type in the GraphQL schema."
input NewPost {
  "The `title` of the Post"
  title: String!
  "The `content` of the Post"
  content: String!
}

type Subscription {
  "Subscribe to new posts."
  newPosts: Post!
}

The repository root has two main directories.

.
├── apollo-social-media-graphql-service
└── ballerina-social-media-graphql-service

Apollo Social Media GraphQL Service

This is a GraphQL service written in typescript using the Apollo GraphQL library. The project is a NodeJS project that uses ExpressJS and Apollo GraphQL along with MySQL2 and other helper libraries.

Source Code

The ts/src directory contains all the source codes for the project.

This directory contains four more directories.

  • auth directory

    This directory contains the source code related to auth functionalities.

  • db directory

    This directory contains the source code to define database operations.

  • graphql directory

    This directory contains the source code to define the GraphQL functionalities including the schema and the resolvers.

  • types directory

    This directory contains the typescript type definitions that are used in the project.

The index.ts and the utils ts files under the src directories are used to define the main functionality of the GraphQL server.

Configurations

The config directory contains the default.json file that contains the default configs for the project. They can be overridden at the runtime as needed.

Resources

The resources directory includes the database initialization script.

Run the Service

  1. Download and install NodeJS

  2. Download and install MySQL

  3. Run the docker image for the Database using the following command:

    docker compose -f docker-compose-apollo-db.yml up

    OR

    Execute the init_db.sql file in the MySQL CLI.

    source resources/init_db.sql
  4. Run the GraphQL service using by executing the following command:

    npm start

    Alternatively, execute the following command to live-reload the server when developing:

    npm start dev

    This will log something similar to this:

    🚀 Server ready at http://localhost:4000/graphql
  5. Open the link in a browser to access the GraphQL service using the Apollo sandbox.

Ballerina Social Media GraphQL Service

Refer ballerina-social-media-graphql-service/README.md

apollo-and-ballerina's People

Contributors

mohamedsabthar avatar thisaruguruge avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.