GraphQL Tutorial for Server-Side Swift with Vapor: Getting Started | raywenderlich.com

For a long time, solving the problem of API integrations between frontend and server-side seemed trivial. You might have stumbled across some HTML form encoding or legacy APIs that relied on SOAP and IML, but most APIs used REST with JSON encoding. While REST looked like the de-facto standard, ironically, it didnā€™t have a defined [ā€¦]


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/21148796-graphql-tutorial-for-server-side-swift-with-vapor-getting-started

Hey, Iā€™d like to share my experience with going through this tutorial.

You have made an excellent point in declaring the types in the Schema in a specific order. This should also be done in the configure file for the migrations, i.e. we have to declare certain migrations before others as they might depend on each other.

One thing I noticed when trying to flesh out the model is that if we declare a dependency on Graphiti in the models, i.e. if we want to pass in the NoArguments to the request for the child relation, this will lead to segmentation fault. This is easily fixed, just wanted to mention. Iā€™m running Swift 5.5.

It is quite enjoyable tutorial otherwise.
Thank you!

Thanks for the tutorial! However, I am getting stuck right at the beginning.
I opened starter project, waited for the dependencies to download, and then tried to run the app, but got errors like
ā€¦TLSConfiguration.swift:24:35: ā€˜tls_protocol_version_tā€™ is only available in macOS 10.15 or newer
ā€¦TLSConfiguration.swift:27:25: ā€˜TLSv10ā€™ is only available in macOS 10.15 or newer
ā€¦TLSConfiguration.swift:29:25: ā€˜TLSv11ā€™ is only available in macOS 10.15 or newer
Command CompileSwiftSources failed with a nonzero exit code (GraphQL)
Command CompileSwiftSources failed with a nonzero exit code (NIOHTTP2)

I am running MacOS 12.3 (Monterey)

I was able to get rid of the errors by updating the various package version numbers. This is the setup which allowed me to compile and run the starter version

// Dependencies

dependencies: [
// :droplet: A server-side Swift web framework.
.package(url: ā€œGitHub - vapor/vapor: šŸ’§ A server-side Swift HTTP web framework.ā€, from: ā€œ4.55.3ā€),
.package(url: ā€œGitHub - vapor/fluent: Vapor ORM (queries, models, and relations) for NoSQL and SQL databasesā€, from: ā€œ4.4.0ā€),
.package(url: ā€œGitHub - vapor/fluent-sqlite-driver: Fluent driver for SQLiteā€, from: ā€œ4.1.0ā€),

// šŸŒ GraphQL

// Vapor Utilities
.package(
  name: "GraphQLKit",
  url: "https://github.com/alexsteinerde/graphql-kit.git",
  from: "2.1.0"
),
// Web Query Page
.package(
  name: "GraphiQLVapor",
  url: "https://github.com/alexsteinerde/graphiql-vapor.git",
  from: "2.2.0"
)

],

I do not know Fluent, but the revert schema name looks incorrect to me.

import Fluent

struct MigrateShows: Migration {
  func prepare(on database: Database) -> EventLoopFuture<Void> {
    return database.schema("shows")
      .id()
      .field("title", .string, .required)
      .field("releaseYear", .int, .required)
      .create()
  }

  func revert(on database: Database) -> EventLoopFuture<Void> {
    return database.schema("reviews").delete()
  }
}