-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(query): add metroStations query
It gets the stations data (name, lines, etc) from the tmb website
- Loading branch information
Albert Alises
committed
Oct 12, 2020
1 parent
8f00bae
commit c9c9e89
Showing
14 changed files
with
281 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"extends": [ | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:prettier/recommended" | ||
], | ||
"plugins": ["node", "@typescript-eslint", "prettier"], | ||
"env": { | ||
"es6": true, | ||
"jest": true, | ||
"node": true | ||
}, | ||
"settings": { | ||
"import/resolver": { | ||
"node": { | ||
"extensions": [".js", ".ts"] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { GraphQLObjectType } from "graphql"; | ||
|
||
import message from "./queries/MessageQuery"; | ||
import metroStations from "./queries/MetroStationsQuery"; | ||
|
||
export default new GraphQLObjectType({ | ||
name: "RootQuery", | ||
description: "Root Query", | ||
fields: { | ||
message, | ||
metroStations | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import MetroStation from "../types/outputs/MetroStation"; | ||
import Error from "../types/outputs/Error"; | ||
import { GraphQLUnionType } from 'graphql'; | ||
import { | ||
connectionArgs, | ||
connectionDefinitions, | ||
connectionFromArray | ||
} from 'graphql-relay'; | ||
import type { | ||
MetroStationsQueryResponse as MetroStationsQueryResponseType, | ||
MetroStationConnection as MetroStationConnectionType | ||
} from "../types"; | ||
|
||
const { connectionType: MetroStationConnection } = connectionDefinitions({ | ||
nodeType: MetroStation, | ||
}); | ||
|
||
//MetroStationQuery response as a union of an error or a connection of MetroLine | ||
const MetroStationsQueryResponse = new GraphQLUnionType({ | ||
name: 'MetroStationsQueryResponse', | ||
types: [Error, MetroStationConnection], | ||
resolveType(value) { | ||
return value.code !== undefined ? Error : MetroStationConnection; | ||
}, | ||
}); | ||
|
||
export default { | ||
type: MetroStationsQueryResponse, | ||
args: connectionArgs, | ||
resolve: (_, args): MetroStationsQueryResponseType => { | ||
return connectionFromArray([{ | ||
id: '43943949', | ||
lines: ['L1'], | ||
name: 'Clot', | ||
location: { | ||
latitude: 2.05, | ||
longitude: 232.4, | ||
} | ||
}], args) as MetroStationConnectionType; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { GraphQLFloat, GraphQLObjectType } from "graphql"; | ||
|
||
export default new GraphQLObjectType({ | ||
name: "Coordinates", | ||
description: "Coordinates (Latitude, Longitude, Altitude), of a given station/stop", | ||
fields: { | ||
latitude: { | ||
type: GraphQLFloat, | ||
}, | ||
longitude: { | ||
type: GraphQLFloat, | ||
}, | ||
altitude: { | ||
type: GraphQLFloat | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { GraphQLObjectType, GraphQLString, GraphQLInt } from "graphql"; | ||
|
||
export default new GraphQLObjectType({ | ||
name: "Error", | ||
description: "Generic Error", | ||
fields: { | ||
code: { | ||
type: GraphQLInt, | ||
description: "HTTP Status Code of the Error" | ||
}, | ||
message: { | ||
type: GraphQLString, | ||
description: "Error Description" | ||
}, | ||
}, | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Coordinates from './Coordinates'; | ||
import { GraphQLObjectType, GraphQLID, GraphQLString, GraphQLList } from "graphql"; | ||
|
||
export default new GraphQLObjectType({ | ||
name: "MetroStation", | ||
description: "Metro station information", | ||
fields: { | ||
id: { | ||
description: "Unique ID of the station", | ||
type: GraphQLID | ||
}, | ||
name: { | ||
description: "Name of the station", | ||
type: GraphQLString | ||
}, | ||
location: { | ||
description: "Location coordinates of the station", | ||
type: Coordinates | ||
}, | ||
lines: { | ||
description: "Lines the station belongs to e.g. L1, L2", | ||
type: GraphQLList(GraphQLString) | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.