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
319const https = require ( 'https' ) ;
420const 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
825function 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 = [];
2746function 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 ) ) ;
0 commit comments