Skip to content

MiguelBrav/GraphQLTest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

GraphQL with Hotchocolate

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages