Skip to content

Commit 12cdc69

Browse files
authored
chore(examples): lint examples/graphql using shared top-level eslint config (#2899)
Refs: #2891
1 parent f2c9707 commit 12cdc69

File tree

11 files changed

+200
-28
lines changed

11 files changed

+200
-28
lines changed

examples/graphql/.eslintrc.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
const baseConfig = require('../../eslint.config');
20+
21+
module.exports = {
22+
...baseConfig,
23+
env: {
24+
node: true,
25+
},
26+
};

examples/graphql/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

examples/graphql/client-federation.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
'use strict';
218

319
const url = require('url');
@@ -27,13 +43,13 @@ function makeRequest(query) {
2743
'Content-Type': 'application/json',
2844
},
2945
};
30-
const req = http.request(options, (res) => {
46+
const req = http.request(options, res => {
3147
const data = [];
32-
res.on('data', (chunk) => data.push(chunk));
48+
res.on('data', chunk => data.push(chunk));
3349
res.on('end', () => {
3450
resolve(data.toString());
3551
});
36-
res.on('error', (err) => {
52+
res.on('error', err => {
3753
reject(err);
3854
});
3955
});

examples/graphql/client.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
'use strict';
218

319
const url = require('url');
@@ -32,13 +48,13 @@ function makeRequest(query) {
3248
'Content-Type': 'application/json',
3349
},
3450
};
35-
const req = http.request(options, (res) => {
51+
const req = http.request(options, res => {
3652
const data = [];
37-
res.on('data', (chunk) => data.push(chunk));
53+
res.on('data', chunk => data.push(chunk));
3854
res.on('end', () => {
3955
resolve(data.toString());
4056
});
41-
res.on('error', (err) => {
57+
res.on('error', err => {
4258
reject(err);
4359
});
4460
});

examples/graphql/countries-service.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
'use strict';
218

319
const { fetch } = require('cross-fetch');

examples/graphql/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"description": "Example of using @opentelemetry/plugin-graphql with OpenTelemetry",
66
"main": "index.js",
77
"scripts": {
8+
"lint": "eslint . --ext=ts,js,mjs",
9+
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
810
"client": "node ./client.js",
911
"client:federation": "node ./client-federation.js",
1012
"docker:start": "cd ./docker && docker-compose down && docker-compose up",

examples/graphql/schema.js

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
'use strict';
218

319
const https = require('https');
420
const graphql = require('graphql');
521

6-
const url1 = 'https://raw.githubusercontent.com/open-telemetry/opentelemetry-js/main/package.json';
22+
const url1 =
23+
'https://raw.githubusercontent.com/open-telemetry/opentelemetry-js/main/package.json';
724

825
function getData(url) {
926
return new Promise((resolve, reject) => {
10-
https.get(url, (response) => {
11-
let data = '';
12-
response.on('data', (chunk) => {
13-
data += chunk;
14-
});
15-
response.on('end', () => {
16-
resolve(JSON.parse(data));
27+
https
28+
.get(url, response => {
29+
let data = '';
30+
response.on('data', chunk => {
31+
data += chunk;
32+
});
33+
response.on('end', () => {
34+
resolve(JSON.parse(data));
35+
});
36+
})
37+
.on('error', err => {
38+
reject(err);
1739
});
18-
}).on('error', (err) => {
19-
reject(err);
20-
});
2140
});
2241
}
2342

@@ -27,7 +46,7 @@ const books = [];
2746
function addBook(name, authorIds) {
2847
let authorIdsLocal = authorIds;
2948
if (typeof authorIdsLocal === 'string') {
30-
authorIdsLocal = authorIdsLocal.split(',').map((id) => parseInt(id, 10));
49+
authorIdsLocal = authorIdsLocal.split(',').map(id => parseInt(id, 10));
3150
}
3251
const id = books.length;
3352
books.push({
@@ -90,7 +109,7 @@ module.exports = function buildSchema() {
90109
type: graphql.GraphQLString,
91110
resolve(_obj, _args) {
92111
return new Promise((resolve, reject) => {
93-
getData(url1).then((response) => {
112+
getData(url1).then(response => {
94113
resolve(response.description);
95114
}, reject);
96115
});
@@ -139,7 +158,7 @@ module.exports = function buildSchema() {
139158
authors: {
140159
type: new graphql.GraphQLList(Author),
141160
resolve(obj, _args) {
142-
return obj.authorIds.map((id) => authors[id]);
161+
return obj.authorIds.map(id => authors[id]);
143162
},
144163
},
145164
},
@@ -188,7 +207,9 @@ module.exports = function buildSchema() {
188207
type: Book,
189208
args: {
190209
name: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) },
191-
authorIds: { type: new graphql.GraphQLNonNull(graphql.GraphQLString) },
210+
authorIds: {
211+
type: new graphql.GraphQLNonNull(graphql.GraphQLString),
212+
},
192213
},
193214
resolve(obj, args, _context) {
194215
return Promise.resolve(addBook(args.name, args.authorIds));

examples/graphql/server-apollo.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
'use strict';
218

319
require('./tracer');

examples/graphql/server-express.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
'use strict';
218

319
require('./tracer');
@@ -9,10 +25,13 @@ const buildSchema = require('./schema');
925
const schema = buildSchema();
1026

1127
const app = express();
12-
app.use('/graphql', graphqlHTTP({
13-
schema,
14-
graphiql: true,
15-
}));
28+
app.use(
29+
'/graphql',
30+
graphqlHTTP({
31+
schema,
32+
graphiql: true,
33+
})
34+
);
1635

1736
app.listen(4000);
1837

examples/graphql/server-federation.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
'use strict';
218

319
require('./tracer');

0 commit comments

Comments
 (0)