{"id":13499543,"url":"https://github.com/GraphQLSwift/GraphQL","last_synced_at":"2025-03-29T05:31:41.815Z","repository":{"id":40692695,"uuid":"70793194","full_name":"GraphQLSwift/GraphQL","owner":"GraphQLSwift","description":"The Swift GraphQL implementation for macOS and Linux","archived":false,"fork":false,"pushed_at":"2024-09-25T15:09:13.000Z","size":815,"stargazers_count":937,"open_issues_count":11,"forks_count":72,"subscribers_count":22,"default_branch":"main","last_synced_at":"2024-10-12T21:02:38.952Z","etag":null,"topics":["graphiti","graphql","swift","swift-nio","swiftpm","vapor"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/GraphQLSwift.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-13T09:56:22.000Z","updated_at":"2024-10-06T14:10:30.000Z","dependencies_parsed_at":"2023-11-11T22:27:45.819Z","dependency_job_id":"10becf41-0afd-4db9-9015-6fda3588ea96","html_url":"https://github.com/GraphQLSwift/GraphQL","commit_stats":{"total_commits":376,"total_committers":29,"mean_commits":12.96551724137931,"dds":0.6968085106382979,"last_synced_commit":"3cf2dbce764e7ccff8447d0b7d4634c0438449d3"},"previous_names":[],"tags_count":70,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GraphQLSwift%2FGraphQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GraphQLSwift%2FGraphQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GraphQLSwift%2FGraphQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GraphQLSwift%2FGraphQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GraphQLSwift","download_url":"https://codeload.github.com/GraphQLSwift/GraphQL/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222465400,"owners_count":16989007,"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":["graphiti","graphql","swift","swift-nio","swiftpm","vapor"],"created_at":"2024-07-31T22:00:34.596Z","updated_at":"2024-10-31T18:30:44.313Z","avatar_url":"https://github.com/GraphQLSwift.png","language":"Swift","readme":"# GraphQL\n\n[![Swift][swift-badge]][swift-url]\n[![SSWG][sswg-badge]][sswg-url]\n[![License][mit-badge]][mit-url]\n[![Codebeat][codebeat-badge]][codebeat-url]\n\n\nThe Swift implementation for GraphQL, a query language for APIs created by Facebook.\n\nLooking for help? Find resources [from the community](http://graphql.org/community/).\n\n## Usage\n\n### Schema Definition\n\nThe `GraphQLSchema` object can be used to define [GraphQL Schemas and Types](https://graphql.org/learn/schema/).\nThese schemas are made up of types, fields, arguments, and resolver functions. Below is an example:\n\n```swift\nlet schema = try GraphQLSchema(\n    query: GraphQLObjectType(                   // Defines the special \"query\" type\n        name: \"Query\",\n        fields: [\n            \"hello\": GraphQLField(              // Users may query 'hello'\n                type: GraphQLString,            // The result is a string type\n                resolve: { _, _, _, _ in\n                    \"world\"                     // The result of querying 'hello' is \"world\"\n                }\n            )\n        ]\n    )\n)\n```\n\nFor more complex schema examples see the test files.\n\nThis repo only contains the core GraphQL implementation and does not focus on the ease of schema creation. For a better experience\nwhen creating your GraphQL schema use [Graphiti](https://github.com/GraphQLSwift/Graphiti).\n\n### Execution\n\nOnce a schema has been defined queries may be executed against it using the global `graphql` function:\n\n```swift\nlet result = try await graphql(\n    schema: schema,\n    request: \"{ hello }\",\n    eventLoopGroup: eventLoopGroup\n)\n```\n\nThe result of this query is a `GraphQLResult` that encodes to the following JSON:\n\n```json\n{ \"hello\": \"world\" }\n```\n\n### Subscription\n\nThis package supports GraphQL subscription, but until the integration of `AsyncSequence` in Swift 5.5 the standard Swift library did not\nprovide an event-stream construct. For historical reasons and backwards compatibility, this library implements subscriptions using an \n`EventStream` protocol that nearly every asynchronous stream implementation can conform to.\n\nTo create a subscription field in a GraphQL schema, use the `subscribe` resolver that returns an `EventStream`. You must also provide a\n`resolver`, which defines how to process each event as it occurs and must return the field result type. Here is an example:\n\n```swift\nlet schema = try GraphQLSchema(\n    subscribe: GraphQLObjectType(\n        name: \"Subscribe\",\n        fields: [\n            \"hello\": GraphQLField(              \n                type: GraphQLString,\n                resolve: { eventResult, _, _, _, _ in       // Defines how to transform each event when it occurs\n                    return eventResult\n                },\n                subscribe: { _, _, _, _, _ in               // Defines how to construct the event stream\n                    let asyncStream = AsyncThrowingStream\u003cString, Error\u003e { continuation in\n                        let timer = Timer.scheduledTimer(\n                            withTimeInterval: 3,\n                            repeats: true,\n                        ) {\n                            continuation.yield(\"world\")     // Emits \"world\" every 3 seconds\n                        }\n                    }\n                    return ConcurrentEventStream\u003cString\u003e(asyncStream)\n                }\n            )\n        ]\n    )\n)\n```\n\nTo execute a subscription use the `graphqlSubscribe` function:\n\n```swift\nlet subscriptionResult = try await graphqlSubscribe(\n    schema: schema,\n)\n// Must downcast from EventStream to concrete type to use in 'for await' loop below\nlet concurrentStream = subscriptionResult.stream! as! ConcurrentEventStream\nfor try await result in concurrentStream.stream {\n    print(result)\n}\n```\n\nThe code above will print the following JSON every 3 seconds:\n\n```json\n{ \"hello\": \"world\" }\n```\n\nThe example above assumes that your environment has access to Swift Concurrency. If that is not the case, try using\n[GraphQLRxSwift](https://github.com/GraphQLSwift/GraphQLRxSwift)\n\n## Encoding Results\n\nIf you encode a `GraphQLResult` with an ordinary `JSONEncoder`, there are no guarantees that the field order will match the query, \nviolating the [GraphQL spec](https://spec.graphql.org/June2018/#sec-Serialized-Map-Ordering). To preserve this order, `GraphQLResult`\nshould be encoded using the `GraphQLJSONEncoder` provided by this package.\n\n## Support\n\nThis package supports Swift versions in [alignment with Swift NIO](https://github.com/apple/swift-nio?tab=readme-ov-file#swift-versions).\n\nFor details on upgrading to new major versions, see [MIGRATION](MIGRATION.md).\n\n## Contributing\n\nIf you think you have found a security vulnerability, please follow the\n[Security guidelines](SECURITY.md).\n\nThose contributing to this package are expected to follow the [Swift Code of Conduct](https://www.swift.org/code-of-conduct/), the\n[Swift API Design Guidelines](https://swift.org/documentation/api-design-guidelines/), and the\n[SSWG Technical Best Practices](https://github.com/swift-server/sswg/blob/main/process/incubation.md#technical-best-practices).\n\nThis repo uses [SwiftFormat](https://github.com/nicklockwood/SwiftFormat), and includes lint checks to enforce these formatting standards.\nTo format your code, install `swiftformat` and run:\n\n```bash\nswiftformat .\n```  \n\nMost of this repo mirrors the structure of\n(the canonical GraphQL implementation written in Javascript/Typescript)[https://github.com/graphql/graphql-js]. If there is any feature\nmissing, looking at the original code and \"translating\" it to Swift works, most of the time. For example:\n\n### Swift\n\n[/Sources/GraphQL/Language/AST.swift](https://github.com/GraphQLSwift/GraphQL/blob/master/Sources/GraphQL/Language/AST.swift)\n\n### Javascript/Typescript\n\n[/src/language/ast.js](https://github.com/graphql/graphql-js/blob/master/src/language/ast.js)\n\n\n## License\n\nThis project is released under the MIT license. See [LICENSE](LICENSE) for details.\n\n[swift-badge]: https://img.shields.io/badge/Swift-5.10-orange.svg?style=flat\n[swift-url]: https://swift.org\n\n[sswg-badge]: https://img.shields.io/badge/sswg-incubating-blue.svg?style=flat\n[sswg-url]: https://swift.org/sswg/incubation-process.html#incubating-level\n\n[mit-badge]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat\n[mit-url]: https://tldrlegal.com/license/mit-license\n\n[gh-actions-badge]: https://github.com/GraphQLSwift/GraphQL/workflows/Build/badge.svg\n[gh-actions-url]: https://github.com/GraphQLSwift/GraphQl/actions?query=workflow%3ABuild\n\n[codebeat-badge]: https://codebeat.co/badges/13293962-d1d8-4906-8e62-30a2cbb66b38\n[codebeat-url]: https://codebeat.co/projects/github-com-graphqlswift-graphql\n","funding_links":[],"categories":["Libraries","Swift","Implementations"],"sub_categories":["Swift Libraries","Swift"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGraphQLSwift%2FGraphQL","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGraphQLSwift%2FGraphQL","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGraphQLSwift%2FGraphQL/lists"}