Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdsupremacist authored Sep 30, 2020
1 parent 7a57f97 commit 7c2331c
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ Let's cut the chase and write our Hello World!
```swift
// Create a GraphQLSchema
enum HelloWorld: GraphQLSchema {

// Describe the Query Type
class Query: QueryType {
func greeting(name: String) -> String {
return "Hello, \(name)"
}
}

typealias Mutation = None

}

// Run a query using .perform
Expand Down Expand Up @@ -159,7 +158,7 @@ And you can see the results immediately:
A Schema is basically the namespace where you define two objects: A Query and a Mutation Type.
The query and mutation behave like regular `GraphQLObject`s. All the features mentioned above will be included out of the box.

The QueryType is mandatory and always has to be defined! If your API doesn't need Mutations, just set it to `None` like we did before.
The QueryType is mandatory and always has to be defined! If your API doesn't need Mutations, then you're done.

**What if you want to make data user dependent?**

Expand All @@ -184,8 +183,18 @@ enum TodoApp: GraphQLSchema {
self.user = user
}
}

class Mutation: MutationType {
let user: LoggedInUser?

func deleteTodo(id: UUID) -> Todo? {
return user?.todos.find(id: id).delete()
}

typealias Mutation = None
required init(viewerContext user: LoggedInUser?) {
self.user = user
}
}
}
```

Expand All @@ -200,10 +209,8 @@ enum HelloWorld: GraphQLSchema {
return "Hello, \(name)"
}

required init(viewerContext: ViewerContext) { }
required init(viewerContext: Void) { }
}

typealias Mutation = None
}
```

Expand Down Expand Up @@ -239,8 +246,6 @@ enum HelloWorld: GraphQLSchema {
class Query: QueryType {
let url = URL(string: "https://github.com/nerdsupremacist/GraphZahl")
}

typealias Mutation = None
}
```

Expand Down Expand Up @@ -403,8 +408,6 @@ enum HelloWorld: GraphQLSchema {
return "Hello, \(name)"
}
}

typealias Mutation = None
}

// Add the API to the Routes of your Vapor App
Expand Down

0 comments on commit 7c2331c

Please sign in to comment.