Code Monkey home page Code Monkey logo

graphqltest's Introduction

GraphQLTest

GraphQLServer

GraphQL Server with Hotchocolate & .Net.

Usage/Examples for GraphQL in .net

You can guide from the unit tests for consuming the graphql api.

        var query = @"
          query getAutores {
            autores {
                pageInfo {
                    hasNextPage
                    hasPreviousPage
                }
                items {
                    id
                    nombre
                    apellidos
                }
                totalCount
            }
        }
        ";

        var request = new
        {
            query
        };

        var json = JsonConvert.SerializeObject(request);
        var content = new StringContent(json, Encoding.UTF8, "application/json");

        // Act
        var response = await _client.PostAsync("graphql", content);

Usage example online

Get Autores

          query getAutores {
            autores {
                pageInfo {
                    hasNextPage
                    hasPreviousPage
                }
                items {
                    id
                    nombre
                    apellidos
                }
                totalCount
            }
        }

Get Autor by Id

        query getAutorById($autorId: Int!){
            autorById(id: $autorId){
            id
            nombre    
            apellidos
            email
            salario
            publicaciones{
              id
              titulo
              imagenUrl
            }
          }
        } 

Create Autor

        mutation addAutor($inputAutor: AutorInputTypeInput!){
          createAutor(inputAutor:  $inputAutor ) {
            id
           nombre
           apellidos
           email
           salario 
          }
        }

Delete Autor

        mutation deleteAutor($autorId: Int!){
                  deleteAutor(autorId:  $autorId ) 
                   
                }

Get Categorias

        query getCategorias{
          categorias {
            items{
              id
              nombre
              publicaciones{
                id
                titulo
                contenido
              }
            },
            totalCount
          }
        }

Get Categoria by Id

        query getCategoriabyId($categoryId: Int!){
          categoriaById(id: $categoryId) {
            id
            nombre
            publicaciones{
              id
              titulo
              contenido
              imagenUrl
  
            }
          }
        }

Get Publicaciones

        query getPublicaciones {
          publicaciones {
            items{
              id
              titulo
              contenido
              imagenUrl
              estado
              rating
              categoriaId
              autorId
            }
            totalCount
          }
        }

Get Publicacion by Id

        query getPublicacionbyId($publicationId: Int!){
        publicacionById(id: $publicationId) {
          id
          titulo
          contenido
          imagenUrl
          estado
          rating
          categoriaId
          autorId
        }
        }

In the section "Variables", you need to add them, like this.

        {
          "inputAutor": {
            "apellidos": "lastname",
            "email": "[email protected]",
            "nombre": "firstname",
            "salario": 1000
          }  
        }

The API is available at: "https://booktestapi.application-service.work/graphql/".

App Screenshot

Running Tests

To run tests, run GraphQLServerTests.cs from project GraphQLServer.NUnitTest

App Screenshot

Feedback

If you have any feedback, please reach out to me.

graphqltest's People

Contributors

miguelbrav avatar

Stargazers

jist avatar Paul Koop avatar

Watchers

 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.