Coder Social home page Coder Social logo

springmonster / netflix-dgs-example-java Goto Github PK

View Code? Open in Web Editor NEW
35.0 3.0 3.0 1020 KB

Java Examples of Netflix DGS

License: MIT License

Java 94.58% Dockerfile 0.11% JavaScript 0.94% Kotlin 4.37%
graphql graphql-server netflix-dgs java spring-boot spring-graphql graphql-java

netflix-dgs-example-java's Introduction

DGS

module description

Module Description
✅a-start Example of multiple *.graphqls,@DgsData.List
✅b-codegen Example of codegen,multiple modules,methods in type,support constant in @DgsData,@RequestHeader
✅c-scalar Example of custom scalar
✅d-http Example of Query,Mutation,Subscription,params validation,Apollo Tracing
✅e-file Example of file upload
✅f-auth Example of authentication and authorization
✅g-error Example of custom error type
✅h-ut Example of uni test, integration test, unit test of supporting custom scalar
✅i-nplusone Example of N+1, support custom tracing
✅j-sample Example of split Query and Mutation into different configruation files to avoid too many definitions in one file
k-postg Example of supporting PostGraphile(Experimental)(TODO)
✅l-interfaceunion Example of interface and union
✅m-dynamicschema Example of dynamic schema
❎n-webflux Example of dynamic webflux, there are problems with Spring Security
✅o-metrics Example of metrics
✅p-apollo-gateway
✅p-federation-customer
✅p-federation-name
✅p-federation-profile
Apollo Federation Gateway
✅o-metrics Example of metrics
✅x-kotlin Example of Kotlin
✅y-bff Example of client and server,support voyager
✅z-domain Example of client and server,support voyager

Intellij Idea Plugin

a-start

{
    shows {
        title
        releaseYear
    }
}
------
{
  shows(titleFilter: "Ozark") {
    title
    releaseYear
  }
}
------
{
  showsWithDgsData {
    id
    title
    releaseYear
    actors {
      name
    }
  }
}
------
{
  user {
    id
    name
  }
}

b-codegen

  • root build.gradle
plugins {
    id "com.netflix.dgs.codegen" version "5.1.17" apply false
}
  • module build.gradle
plugins {
    id "com.netflix.dgs.codegen"
}
  • module build.gradle
generateJava{
    schemaPaths = ["${projectDir}/src/main/resources/schema"] // List of directories containing schema files
    packageName = 'com.codegen.graphqldgs' // The package name to use to generate sources
    generateClient = true // Enable generating the type safe query API
}
{
  shows {
    id
    title
    releaseYear
  }
}
------
{
  shows(titleFilter: "Ozark") {
    id
    title
    releaseYear
  }
}

c-scalar

{
  shows {
    id
    title
    releaseYear
    price
    dateTime
    bigDecimal
    uuid
  }
}

d-http

{
  show(people: {name: "zhangsan"}) {
    id
    name
  }
  shows(personList: [{name: "zhangsan"}]) {
    id
    name
  }
}
------
{
  showWithGood {
    id
    name
  }
}
------
{
  showWithGood(good: {name: "Car"}) {
    id
    name
  }
}
------
mutation {
  addRating(title: "title", stars: 100) {
    avgStars
  }
  addRatingWithInput(input: {title: "title", stars: 200}) {
    avgStars
  }
}
------
mutation {
  addRating(title: "title", stars: 100) {
    avgStars
  }
  addRatingWithInput(input: {title: "hel", stars: 200}) {
    avgStars
  }
}

Use Postman to visit Subscription img.png

e-file

  • Startup
  • Input with curl
curl localhost:10005/graphql \
  -F operations='{ "query": "mutation upload($file: Upload!) { upload(file: $file) }" , "variables": { "file": null } }' \
  -F map='{ "0": ["variables.file"] }' \
  -F [email protected]
------
curl localhost:10005/graphql \
  -F operations='{ "query": "mutation addArtwork($file: Upload!) { addArtwork(file: $file) }" , "variables": { "file": null } }' \
  -F map='{ "0": ["variables.file"] }' \
  -F [email protected]

  • Output

Please check project uploaded-images folder

{"data":{"upload":true}}
------
{"data":{"addArtwork":true}}

f-auth

{
  salary
}
------
{
  salary
}
# REQUEST HEADERS中Input{ "Authorization": "Basic aHI6aHI=" },This is hr username and password
------
mutation {
  updateSalary(salaryInput: {employeeId: "1", newSalary: "100"}) {
    id
    employeeId
    newSalary
  }
}
------
mutation {
  updateSalary(salaryInput: {employeeId: "1", newSalary: "100"}) {
    id
    employeeId
    newSalary
  }
}
# REQUEST HEADERS中Input{ "Authorization": "Basic aHI6aHI=" },This is hr username and password

g-error

{
  show(people: {name: "haha"}) {
    id
    name
  }
}
------
{
  show(people: {name: "zhangsan"}) {
    id
    name
  }
}
------
{
  getRating(id: "1") {
    avgStars
  }
}

h-ut

see test folder

  • Run DemoControllerTests and ShowDataFetcherTest to check

i-nplusone

{
  shows {
    showId
    title
    reviews {
      starRating
    }
  }
}
------
{
  showsN {
    id
    title
    releaseYear
    artwork {
      url
    }
    reviewsN {
      username
      starScore
      submittedDate
    }
  }
}

l-interfaceunion

{
  movies {
    __typename
    ... on ActionMovie {
      title
      nrOfExplosions
    }
    ... on ScaryMovie {
      title
      gory
      scareFactor
    }
  }
}
  • union input
{
  search {
    __typename
    ... on Actor {
      name
    }
    ... on Series {
      title
    }
  }
}

m-dynamicschema

query randomNumber {
  randomNumber(bound: 10)
}
------
mutation createUser {
  createUser(username: "hello", password: "world") {
    id
    username
    password
  }
}

n-webflux

query getUsers {
  getUsers {
    id
    username
    password
  }
  getUserById(id: 1) {
    id
    username
    password
  }
}

mutation createUser {
  createUser(username: "Trudy", password: "Trudy") {
    id
    username
    password
  }
}

o-metrics

visit http://localhost:10015/actuator/metrics to check output

Step 1

Use docker-compose to start Grafana and Prometheus servers.

  • First generate jar in /build/libs folder
  • In the root folder
docker-compose up -d

Step 2

Check the Prometheus server.

Step 3

Configure the Grafana.

p-gateway

Step 1

Start customer,name,profile services

Step 2

Start Apollo Gateway

npm install

node index.js

Step 3

Visit http://localhost:4000

Variables is

{
  "customerId": "1"
}

Query is

query Customer($customerId: String!) {
  customer(customerId: $customerId) {
    age
    id
    name {
      firstName
      fullName
      lastName
      middleName
      prefix
    }
    profile {
      email
      phone
    }
  }
}

x-kotlin

  • Input
{
	shows {
    title
    releaseYear
	  id
	}
}

y-bff

{
  shows {
    id
    title
    releaseYear
  }
}
------
mutation {
  addShow(input: {title: "title", releaseYear: 2022}) {
    id
    title
    releaseYear
  }
}

z-domain

{
  shows {
    id
    title
    releaseYear
  }
}
------
mutation {
  addShow(input: {title: "title", releaseYear: 2022}) {
    id
    title
    releaseYear
  }
}

netflix-dgs-example-java's People

Contributors

dependabot[bot] avatar springmonster avatar tyzzt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.