FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

VerifyTests/Verify.GraphQL: Adds Verify support to verify GraphQL. · GitHub

Latest commit

 

History

41 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Verify.GraphQL

Adds Verify support to verify GraphQL.

See Milestones for release notes.

NuGet

Usage

[ModuleInitializer]
public static void Initialize() =>
    VerifyGraphQL.Initialize();

snippet source | anchor

Result with data

[Test]
public Task ExecutionResultWithData()
{
    var result = new ExecutionResult
    {
        Executed = true,
        Data = new Dictionary<string, object?>
        {
            {
                "user", new Dictionary<string, object?>
                {
                    {
                        "name", "John"
                    },
                    {
                        "age", 30
                    }
                }
            }
        }
    };
    return Verify(result);
}

snippet source | anchor

Result:

{
  Data: {
    user: {
      age: 30,
      name: John
    }
  }
}

snippet source | anchor

Result with errors

[Test]
public Task ExecutionResultWithErrors()
{
    var error = new ExecutionError("Some error")
    {
        Path = ["query", "user"]
    };
    error.AddLocation(new(1, 5));

    var result = new ExecutionResult
    {
        Executed = true,
        Errors = [error]
    };
    return Verify(result);
}

snippet source | anchor

Result:

{
  Errors: [
    {
      Message: Some error,
      Locations: [
        {
          Line: 1,
          Column: 5
        }
      ],
      Path: [
        query,
        user
      ]
    }
  ]
}

snippet source | anchor

Result with extensions

[Test]
public Task ExecutionResultWithExtensions()
{
    var result = new ExecutionResult
    {
        Executed = true,
        Data = new Dictionary<string, object?>
        {
            {
                "hello", "world"
            }
        },
        Extensions = new()
        {
            {
                "tracing", "some-trace-data"
            }
        }
    };
    return Verify(result);
}

snippet source | anchor

Result:

{
  Data: {
    hello: world
  },
  Extensions: {
    tracing: some-trace-data
  }
}

snippet source | anchor

Full result

[Test]
public Task ExecutionResultFull()
{
    var error = new ExecutionError("Some error")
    {
        Path = ["query", "user"]
    };
    error.AddLocation(new(1, 5));

    var result = new ExecutionResult
    {
        Executed = true,
        Data = new Dictionary<string, object?>
        {
            {
                "hello", "world"
            }
        },
        Errors = [error],
        Extensions = new()
        {
            {
                "tracing", "some-trace-data"
            }
        }
    };
    return Verify(result);
}

snippet source | anchor

Result:

{
  Errors: [
    {
      Message: Some error,
      Locations: [
        {
          Line: 1,
          Column: 5
        }
      ],
      Path: [
        query,
        user
      ]
    }
  ],
  Data: {
    hello: world
  },
  Extensions: {
    tracing: some-trace-data
  }
}

snippet source | anchor

Not executed result

[Test]
public Task ExecutionResultNotExecuted()
{
    var result = new ExecutionResult
    {
        Executed = false,
        Data = new Dictionary<string, object?>
        {
            {
                "hello", "world"
            }
        }
    };
    return Verify(result);
}

snippet source | anchor

Result:

{}

snippet source | anchor

GraphQL request

[Test]
public Task GraphQLRequest()
{
    var request = new GraphQLRequest
    {
        Query = "{ hero { name } }",
        OperationName = "HeroQuery",
        Variables = new(
            new Dictionary<string, object?>
            {
                {
                    "id", "1"
                }
            }),
        Extensions = new(
            new Dictionary<string, object?>
            {
                {
                    "tracing", true
                }
            })
    };
    return Verify(request);
}

snippet source | anchor

Result:

{
  Query: { hero { name } },
  OperationName: HeroQuery,
  Variables: {
    id: 1
  },
  Extensions: {
    tracing: true
  }
}

snippet source | anchor

Operation message

[Test]
public Task OperationMessage()
{
    var message = new OperationMessage
    {
        Type = "connection_init",
        Id = "1",
        Payload = new Dictionary<string, object?>
        {
            {
                "query", "{ hero { name } }"
            }
        }
    };
    return Verify(message);
}

snippet source | anchor

Result:

{
  Type: connection_init,
  Id: 1,
  Payload: {
    query: { hero { name } }
  }
}

snippet source | anchor

About

Adds Verify support to verify GraphQL.

Resources

Stars

1 star

Watchers

0 watching

Forks

Used by

Contributors

Languages


Back | FazBrowse Home | New Git URL