Coder Social home page Coder Social logo

pallavichaudhari / example-orders Goto Github PK

View Code? Open in Web Editor NEW

This project forked from graphql-dotnet/example-orders

0.0 0.0 0.0 511 KB

GraphQL order management example

License: Apache License 2.0

C# 1.61% CSS 2.63% JavaScript 95.39% HTML 0.38%

example-orders's Introduction

Example-Orders

A sample GraphQL order management endpoint using GraphQL for .NET. This is a more advanced version of the example I used in my course API Development in .NET with GraphQL

Running the sample

  • If using Visual Studio, open Orders-GraphQL.sln build and run
  • On Mac/Linux go the Server folder and run dotnet run -f netcoreapp2.0

Overview

This endpoint contains 2 core data types

  • Orders - Orders that have been added to the system
  • Customers - Customers for each order

API

Queries

orders

Retrieves a list of orders

example:

query getOrders {
  orders {
    id
    name
    description
    customer {
        name
    }
  }
}

orderById

Retrieves a specified order

Arguments

  • orderId - The id of the order

example:

query getOrder {
  orderById(orderId: "FAEBD971-CBA5-4CED-8AD5-CC0B8D4B7827") {
    id
    name
    description
  }
}

customers

Retrieves all customers

example:

query getCustomers {
  customers {
    id
    name
  }
}

Mutations

createOrder

Creates an order

Arguments

  • order - Information for the order to be created.

example:

mutation createOrder{
  createOrder(order:
    {
      name:"Glenn",
      description:"Test",
      customerId: 1,
      created: "03/16/2018"
    }
  ) 
  {
    id
    name
  }
}

startOrder

Starts the processing of an order. Can only be called if the order is in a CREATED state.

Arguments

  • orderId - The id of the order

example starting an order

mutation startOrder {
  startOrder(orderId: "FAEBD971-CBA5-4CED-8AD5-CC0B8D4B7827") {
    id
    status
  }
}

completeOrder

Finishes the processing of an order. Can only be called if the order is in the PROCESSING state.

Arguments

  • orderId - The id of the order

example completing an order

mutation completeOrder {
  completeOrder(orderId: "FAEBD971-CBA5-4CED-8AD5-CC0B8D4B7827") {
    id
    status
  }
}

cancelOrder

Cancels an order. Can only be called if the order is not in the COMPLETED or CANCELLED state.

Arguments

  • orderId - The id of the order

example cancelling an order

mutation cancelOrder {
  cancelOrder(orderId: "FAEBD971-CBA5-4CED-8AD5-CC0B8D4B7827") {
    id
    status
  }
}

closeOrder

Closes an order. Can only be called if the order is in the COMPLETED state.

Arguments

  • orderId - The id of the order

example closing an order

mutation closeOrder {
  closeOrder(orderId: "FAEBD971-CBA5-4CED-8AD5-CC0B8D4B7827") {
    id
    status
  }
}

Subscriptions

You can use subscriptions to get notified when an order is created. This relies on the awesome GraphQL Server project.

To test out subscriptions, you'll want to open two graphiql instances. One for subscribing, and the other for performing a mutation.

orderEvent

Notifies when order status changes.

Arguments

  • statuses (optional) - An array of one or more statuses to receive notifications on

example subscribing to all order updates

subscription createdEvent {
  orderEvent {
    id
    name
    status
  }
}

example subscribing to order started events

subscription startedEvent {
  orderEvent ([PROCESSING]) {
    id
    name
    status
  }
}

Solution Structure

  • Server - Contains the GraphQL Server / wires up GraphQL.NET middleware
  • Orders - Contains models and the GraphQL Schema
    • Models - Contains the underlying models which drive the schema
    • Services - Contains data services for retrieving and updating models, as well as for notifications. Services are registered with the ASP.NET Core container allowing them to be injected wherever need.
    • Schema - Contains the GraphQL types, queries, mutuations and subscriptions.

License

Apache 2.0

example-orders's People

Contributors

dimapasko avatar glennblock avatar sungam3r 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.