{"id":16476008,"url":"https://github.com/softprops/zig-graphql","last_synced_at":"2025-03-23T11:32:57.611Z","repository":{"id":230108343,"uuid":"778423455","full_name":"softprops/zig-graphql","owner":"softprops","description":"a basic GraphQL client for zig","archived":false,"fork":false,"pushed_at":"2024-06-21T03:25:15.000Z","size":41,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-17T12:00:06.066Z","etag":null,"topics":["gql","graphql","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/softprops.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"softprops"}},"created_at":"2024-03-27T17:38:46.000Z","updated_at":"2025-01-20T23:27:32.000Z","dependencies_parsed_at":"2024-04-20T23:24:46.344Z","dependency_job_id":"9349c6f9-9dce-4aab-bb15-be454a9bacf3","html_url":"https://github.com/softprops/zig-graphql","commit_stats":null,"previous_names":["softprops/zig-gql","softprops/zig-graphql"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Fzig-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Fzig-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Fzig-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softprops%2Fzig-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softprops","download_url":"https://codeload.github.com/softprops/zig-graphql/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245097158,"owners_count":20560311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gql","graphql","zig"],"created_at":"2024-10-11T12:41:16.393Z","updated_at":"2025-03-23T11:32:57.201Z","avatar_url":"https://github.com/softprops.png","language":"Zig","funding_links":["https://ko-fi.com/softprops"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n    zig graphql\n\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n    A very basic GraphQL HTTP client for zig\n\u003c/div\u003e\n\n---\n\n[![ci](https://github.com/softprops/zig-graphql/actions/workflows/ci.yml/badge.svg)](https://github.com/softprops/zig-graphql/actions/workflows/ci.yml) ![License Info](https://img.shields.io/github/license/softprops/zig-graphql) ![Releases](https://img.shields.io/github/v/release/softprops/zig-graphql) [![Zig Support](https://img.shields.io/badge/zig-0.13.0-black?logo=zig)](https://ziglang.org/documentation/0.13.0/)\n\n## examples\n\n```zig\nconst std = @import(\"std\");\nconst graphql = @import(\"graphql\");\n\npub fn main() !void {\n    var gpa = std.heap.GeneralPurposeAllocator(.{}){};\n    defer _ = gpa.deinit();\n    const allocator = gpa.allocator();\n\n    const authz = if (std.posix.getenv(\"GH_TOKEN\")) |pat| blk: {\n        var buf: [400]u8 = undefined;\n        break :blk try std.fmt.bufPrint(\n            \u0026buf,\n            \"bearer {s}\",\n            .{pat},\n        );\n    } else {\n        std.log.info(\"Required GH_TOKEN env var containing a GitHub API token - https://github.com/settings/tokens\", .{});\n        return;\n    };\n\n    // 👇 constructing a client\n    var github = try graphql.Client.init(\n        allocator,\n        .{\n            .endpoint = .{ .url = \"https://api.github.com/graphql\" },\n            .authorization = authz,\n        },\n    );\n    defer github.deinit();\n\n    // 👇 sending a request\n    const result = github.send(\n        .{\n            .query =\n            \\\\query test {\n            \\\\  search(first: 100, type: REPOSITORY, query: \"topic:zig\") {\n            \\\\      repositoryCount\n            \\\\  }\n            \\\\}\n            ,\n        },\n        // 👇 struct representing returned data, this maybe be an adhoc or named struct\n        //    you want this to line up with the shape of your query\n        struct {\n            search: struct {\n                repositoryCount: usize,\n            },\n        },\n    );\n\n    // 👇 handle success and error\n    if (result) |resp| {\n        defer resp.deinit();\n        switch (resp.value.result()) {\n            .data =\u003e |data| std.debug.print(\n                \"zig repo count {any}\\n\",\n                .{data.search.repositoryCount},\n            ),\n            .errors =\u003e |errors| {\n                for (errors) |err| {\n                    std.debug.print(\"Error: {s}\", .{err.message});\n                    if (err.path) |p| {\n                        const path = try std.mem.join(allocator, \"/\", p);\n                        defer allocator.free(path);\n                        std.debug.print(\" @ {s}\", .{path});\n                    }\n                }\n            },\n        }\n    } else |err| {\n        std.log.err(\n            \"Request failed with {any}\",\n            .{err},\n        );\n    }\n}\n```\n\n## 📼 installing\n\nCreate a new exec project with `zig init-exe`. Copy the echo handler example above into `src/main.zig`\n\nCreate a `build.zig.zon` file to declare a dependency\n\n\u003e .zon short for \"zig object notation\" files are essentially zig structs. `build.zig.zon` is zigs native package manager convention for where to declare dependencies\n\nStarting in zig `0.12.0`, you can use\n\n```sh\nzig fetch --save https://github.com/softprops/zig-graphql/archive/refs/tags/v0.2.2.tar.gz\n```\n\nto manually add it as follows\n\n```zig\n.{\n    .name = \"my-app\",\n    .version = \"0.1.0\",\n    .dependencies = .{\n        // 👇 declare dep properties\n        .graphql = .{\n            // 👇 uri to download\n            .url = \"https://github.com/softprops/zig-graphql/archive/refs/tags/v0.2.2.tar.gz\",\n            // 👇 hash verification\n            .hash = \"{current-hash-here}\",\n        },\n    },\n    .paths = .{\"\"},\n}\n```\n\n\u003e the hash below may vary. you can also depend any tag with `https://github.com/softprops/zig-graphql/archive/refs/tags/v{version}.tar.gz` or current main with `https://github.com/softprops/zig-graphql/archive/refs/heads/main/main.tar.gz`. to resolve a hash omit it and let zig tell you the expected value.\n\nAdd the following in your `build.zig` file\n\n```diff\nconst std = @import(\"std\");\n\npub fn build(b: *std.Build) void {\n    const target = b.standardTargetOptions(.{});\n\n    const optimize = b.standardOptimizeOption(.{});\n+    // 👇 de-reference graphql dep from build.zig.zon\n+    const graphql = b.dependency(\"graphql\", .{\n+        .target = target,\n+        .optimize = optimize,\n+    }).module(\"graphql\");\n    var exe = b.addExecutable(.{\n        .name = \"your-exe\",\n        .root_source_file = b.path(\"src/main.zig\"),\n        .target = target,\n        .optimize = optimize,\n    });\n+    // 👇 add the graphql module to executable\n+    exe.root_module.addImport(\"graphql\", graphql);\n\n    b.installArtifact(exe);\n}\n```\n\n## 🥹 for budding ziglings\n\nDoes this look interesting but you're new to zig and feel left out? No problem, zig is young so most us of our new are as well. Here are some resources to help get you up to speed on zig\n\n- [the official zig website](https://ziglang.org/)\n- [zig's one-page language documentation](https://ziglang.org/documentation/0.13.0/)\n- [Learning Zig](https://www.openmymind.net/learning_zig/)\n- [ziglings exercises](https://codeberg.org/ziglings/exercises/)\n\n\\- softprops 2024\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftprops%2Fzig-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftprops%2Fzig-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftprops%2Fzig-graphql/lists"}