Skip to content

Commit f7020ac

Browse files
committed
add individual resource query lookup
1 parent 0889c73 commit f7020ac

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@ Serverless GraphQL API built with Netlify functions and Apollo. This is a POC us
1212
> ntl dev ## this will run your server locally
1313
```
1414

15+
## Running GraphQL queries
16+
17+
We will use the handly GraphQL [playground](https://github.com/prisma/graphql-playground) app to test/run queries against our GraphQL API.
18+
19+
Enter the following url: `http://localhost:8888/.netlify/functions/graphql` in GraphQL playground.
20+
21+
GetAll Resources:
22+
23+
```
24+
{
25+
resources {
26+
id
27+
title
28+
description
29+
credit
30+
url
31+
}
32+
}
33+
```
34+
1535
## Technologies used
1636

1737
- Netlify

src/lambda/resolvers/resources.resolvers.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
// will switch over to a real db for data sources once we vet the POC
12
const resources = [
23
{
3-
id: 1,
4+
id: '1',
45
title: 'Learning React',
56
description: 'Official react tutorial',
67
url: 'https://reactjs.org/tutorial/tutorial.html',
@@ -22,7 +23,7 @@ const resources = [
2223
]
2324
},
2425
{
25-
id: 2,
26+
id: '2',
2627
title: 'Learning Vue',
2728
description: 'Official Vuejs tutorial',
2829
url: 'https://vuejs.org/v2/guide/',
@@ -54,6 +55,11 @@ const resources = [
5455

5556
module.exports = {
5657
Query: {
57-
resources: () => resources
58+
resources: () => resources,
59+
resource: (parent, args, context, info) => {
60+
return resources.find(resource => {
61+
return resource.id === args.id;
62+
});
63+
}
5864
}
5965
};

src/lambda/types/resources.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
type Query {
22
resources: [Resource]!
3+
resource(id: ID!): Resource
34
}
45

56
type Resource {

0 commit comments

Comments
 (0)