Skip to content

Commit 544a214

Browse files
Merge pull request #1 from marvelapp/feature/new-graphql-schema
Update to work with the new Marvel GraphQL Schema
2 parents 939a28f + 8ddfff4 commit 544a214

7 files changed

Lines changed: 71 additions & 40 deletions

File tree

Sources/App/Controllers/Slack/SlackAddPeopleController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ final class SlackAddPeopleController {
163163

164164

165165
// Check if error
166-
if let errorMessage = result.data["errors"]?["message"]?.string{
166+
if let errorMessage = result.data["errors"]?.array?.first?["message"]?.string{
167167
return try Error.custom(text: errorMessage)
168168
}
169169

Sources/App/Controllers/Slack/SlackExternalController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ final class SlackExternalController {
3434

3535
// Compare the verifications token (Security)
3636
if vertificationTokenRequest != verificationToken{
37+
Swift.print("Verification tokens don't match")
3738
throw Abort.badRequest
3839
}
3940

4041
// Check if known callback
4142
guard let slackCallback = SlackExternalCallbacks(rawValue: name) else{
43+
Swift.print("Callback id with '\(name)' doesn't exist")
4244
throw Abort.badRequest
4345
}
4446

Sources/App/Controllers/Slack/SlackProjectsController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ final class SlackProjectsController {
107107
[
108108
"title": projectFound.name,
109109
"title_link": projectFound.prototypeUrl,
110-
"thumb_url": projectFound.images.first?.url ?? "",
110+
"thumb_url": projectFound.screens.first?.content?.url ?? "",
111111
"footer": "Marvel Prototyping",
112112
"fields": [
113113
[

Sources/App/Tools/Marvel/GraphQueries.swift

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,41 +37,47 @@ final class GraphQueries {
3737

3838
static let projects =
3939
"""
40+
fragment image on ImageScreen {
41+
filename
42+
url
43+
}
44+
4045
query {
41-
user {
42-
projects(first: 50) {
43-
edges {
44-
node {
45-
pk
46-
name
47-
prototypeUrl
48-
lastModified
49-
collaborators {
46+
user {
47+
projects(first: 40) {
5048
edges {
5149
node {
5250
pk
53-
username
54-
email
55-
}
56-
}
57-
}
58-
images {
59-
edges {
60-
node {
61-
displayName
62-
fileName
63-
url
64-
width
65-
height
66-
uuid
51+
name
52+
prototypeUrl
53+
lastModified
54+
collaborators {
55+
edges {
56+
node {
57+
pk
58+
username
59+
email
60+
}
61+
}
62+
}
63+
screens(first: 2) {
64+
edges {
65+
node {
66+
name
67+
uuid
68+
modifiedAt
69+
content {
70+
__typename
71+
... image
72+
}
73+
}
74+
}
75+
}
6776
}
6877
}
6978
}
7079
}
7180
}
72-
}
73-
}
74-
}
7581
"""
7682

7783
static func createProject(name: String) -> String{
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// MarvelContent.swift
3+
// App
4+
//
5+
// Created by Maxime De Greve on 06/03/2018.
6+
//
7+
8+
import Vapor
9+
10+
final class MarvelContent {
11+
12+
// Non optionals
13+
var fileName = ""
14+
var url = ""
15+
16+
init(with node: Node?) {
17+
fileName = node?["filename"]?.string ?? ""
18+
url = node?["url"]?.string ?? ""
19+
}
20+
21+
}

Sources/App/Tools/Marvel/MarvelProject.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class MarvelProject {
1515
var name = ""
1616
var prototypeUrl = ""
1717
var lastModified = Date()
18-
var images = [MarvelImage]()
18+
var screens = [MarvelScreen]()
1919
var collaborators = [MarvelMember]()
2020

2121
init(with node: Node?) {
@@ -28,10 +28,10 @@ final class MarvelProject {
2828
lastModified = date
2929
}
3030

31-
if let imagesArray = node?["images"]?["edges"]?.array {
32-
for image in imagesArray{
33-
let image = MarvelImage(with: image["node"])
34-
images.append(image)
31+
if let screensArray = node?["screens"]?["edges"]?.array {
32+
for screen in screensArray{
33+
let screen = MarvelScreen(with: screen["node"])
34+
screens.append(screen)
3535
}
3636
}
3737

Sources/App/Tools/Marvel/MarvelImage.swift renamed to Sources/App/Tools/Marvel/MarvelScreen.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,25 @@
77

88
import Vapor
99

10-
final class MarvelImage {
10+
final class MarvelScreen {
1111

1212
// Non optionals
1313
var uuid = ""
1414
var width = 0
1515
var height = 0
16-
var displayName = ""
17-
var fileName = ""
18-
var url = ""
16+
var name = ""
17+
var content: MarvelContent?
1918

2019
init(with node: Node?) {
2120
uuid = node?["uuid"]?.string ?? ""
2221
width = node?["width"]?.int ?? 0
2322
height = node?["height"]?.int ?? 0
24-
url = node?["url"]?.string ?? ""
25-
fileName = node?["fileName"]?.string ?? ""
26-
displayName = node?["displayName"]?.string ?? ""
23+
name = node?["name"]?.string ?? ""
24+
25+
if let contentNode = node?["content"]{
26+
content = MarvelContent(with: contentNode)
27+
}
28+
2729
}
2830

2931
}

0 commit comments

Comments
 (0)