GraphQLBridge 8.0.0

dotnet add package GraphQLBridge --version 8.0.0
                    
NuGet\Install-Package GraphQLBridge -Version 8.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GraphQLBridge" Version="8.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GraphQLBridge" Version="8.0.0" />
                    
Directory.Packages.props
<PackageReference Include="GraphQLBridge" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GraphQLBridge --version 8.0.0
                    
#r "nuget: GraphQLBridge, 8.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=GraphQLBridge&version=8.0.0
                    
Install GraphQLBridge as a Cake Addin
#tool nuget:?package=GraphQLBridge&version=8.0.0
                    
Install GraphQLBridge as a Cake Tool

GraphQLBridge

GraphQLBridge is a .NET middleware that allows you to route GraphQL queries and mutations to standard ASP.NET controller methods without requiring a separate GraphQL schema definition.

NuGet Version NuGet Downloads

Purpose

If you want to use GraphQL in your frontend application but don't want to maintain a separate GraphQL schema, GraphQLBridge allows you to use your existing ASP.NET controller methods directly. This means you can leverage your existing RESTful APIs without the overhead of defining a GraphQL schema in the backend. The frontend can be setup to use GraphQ queries and mutations, while the backend remains unchanged.

Installation

Install via NuGet Package Manager:

Install-Package GraphQLBridge

Or via .NET CLI:

dotnet add package GraphQLBridge

Quick Start

To get started, add the middleware to your ASP.NET Core application:

using GraphQLBridge.Extensions;

var app = builder.Build();

app.UseGraphQLBridge();

app.UseRouting();

Features

  • Seamless translation from GraphQL queries to REST controller methods.
  • Fragment support.
  • Full support for query, mutation, and parameter binding.
  • Minimal setup—just decorate your controller methods with [GraphQLBridgeResolver("fieldName")].

Usage

.NET Setup

using GraphQLBridge.Attributes;
using Microsoft.AspNetCore.Mvc;

namespace GraphQLBridge.App.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class UserController : ControllerBase
    {
        [HttpGet("{id}")]
        [GraphQLBridgeResolver("getUser")]
        public async Task<User> GetUser(int id)
        {
            await Task.Delay(20);
            return new User { Id = id, Name = $"User{id}", Age = 20 };
        }

        [HttpPost]
        [GraphQLBridgeResolver("createUser")]
        public async Task<User> CreateUser([FromBody] UserInput input)
        {
            await Task.Delay(20);
            return new User { Id = 999, Name = input.Name, Age = input.Age };
        }

        [HttpGet]
        [GraphQLBridgeResolver("listUsers")]
        public async Task<User[]> ListUsers(int page = 1, int pageSize = 10)
        {
            await Task.Delay(20);
            return Enumerable.Range(1, pageSize)
                             .Select(i => new User { Id = i, Name = $"User{i}", Age = 20 })
                             .ToArray();
        }
    }

    public class User { public int Id { get; set; } public string Name { get; set; } public int Age { get; set; } }
    public class UserInput { public string Name { get; set; }  public int Age { get; set; } = 0; }
}

Node.js Client

Install the required dependency:

npm install graphql-request

Create a file like src/index.js:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
import { GraphQLClient, gql } from 'graphql-request';

const client = new GraphQLClient('http://localhost:5001/graphql-bridge');

async function runTests() {
  const query = gql`
    fragment userFields on User {
      id
      name
      age
    }

    query {
      getUser(id: 1) {
        ...userFields
      }
      listUsers(page: 1, pageSize: 3) {
        ...userFields
      }
    }
  `;

  try {
    const data = await client.request(query);
    console.log(JSON.stringify(data, null, 2));
  } catch (e) {
    console.error(e);
  }

  const mutation = gql`
    mutation {
      createUser(input: { name: "New User", age: 11 }) {
        id
        name
        age
      }
    }
  `;

  try {
    const data = await client.request(mutation);
    console.log(JSON.stringify(data, null, 2));
  } catch (e) {
    console.error(e);
  }
}

runTests();

package.json

{
  "name": "graphqlbride-node",
  "version": "1.0.0",
  "main": "src/index.js",
  "scripts": {
    "dev": "node src/index.js"
  },
  "dependencies": {
    "graphql-request": "^7.2.0"
  },
  "type": "module"
}

License

MIT

Author

Created and Maintained by: Ethern-Myth


Give a like to this project, Thanks.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.0 131 5/28/2025