File tree Expand file tree Collapse file tree 12 files changed +1072
-89
lines changed
Expand file tree Collapse file tree 12 files changed +1072
-89
lines changed Original file line number Diff line number Diff line change 33 "private" : true ,
44 "dependencies" : {
55 "@tinyhttp/app" : " workspace:*" ,
6- "formidable" : " ^3.2.5 "
6+ "formidable" : " ^3.5.0 "
77 },
88 "type" : " module" ,
99 "scripts" : {
1010 "start" : " node index.js"
11+ },
12+ "devDependencies" : {
13+ "@types/formidable" : " ^3.4.0"
1114 }
1215}
Original file line number Diff line number Diff line change @@ -17,5 +17,5 @@ node index.js
1717Open [ GraphiQL] ( http://localhost:3000/graphql ) in the browser, or try with ` curl ` :
1818
1919``` sh
20- curl 'http://localhost:3000/graphql?query=%23%20Welcome%20to%20GraphiQL%0A%23%0A%23%20GraphiQL%20is%20an%20in-browser%20tool%20for%20writing%2C%20validating%2C%20and%0A%23%20testing%20GraphQL%20queries.%0A%23%0A%23%20Type%20queries%20into%20this%20side%20of%20the%20screen%2C%20and%20you%20will%20see%20intelligent%0A%23%20typeaheads%20aware%20of%20the%20current%20GraphQL%20type%20schema%20and%20live%20syntax%20and%0A%23%20validation%20errors%20highlighted%20within%20the%20text.%0A%23%0A%23%20GraphQL%20queries%20typically%20start%20with%20a%20%22%7B%22%20character.%20Lines%20that%20start%0A%23%20with%20a%20%23%20are%20ignored.%0A%23%0A%23%20An%20example%20GraphQL%20query%20might%20look%20like%3A%0A%23%0A%23%20%20%20%20%20%7B%0A%23%20%20%20%20%20%20%20field(arg%3A%20%22value%22)%20%7B%0A%23%20%20%20%20%20%20%20%20%20subField%0A%23%20%20%20%20%20%20%20%7D%0A%23%20%20%20%20%20%7D%0A%23%0A%23%20Keyboard%20shortcuts%3A%0A%23%0A%23%20%20Prettify%20Query%3A%20%20Shift-Ctrl-P%20(or%20press%20the%20prettify%20button%20above)%0A%23%0A%23%20%20%20%20%20Merge%20Query%3A%20%20Shift-Ctrl-M%20(or%20press%20the%20merge%20button%20above)%0A%23%0A%23%20%20%20%20%20%20%20Run%20Query%3A%20%20Ctrl-Enter%20(or%20press%20the%20play%20button%20above)%0A%23%0A%23%20%20%20Auto%20Complete%3A%20%20Ctrl-Space%20(or%20just%20start%20typing)%0A%23%0A%0A%7B%0A%20%20hello%0A%7D'
20+ curl ' http://localhost:3000/graphql?query={%0A++hello%0A}'
2121```
Original file line number Diff line number Diff line change 11import { App } from '@tinyhttp/app'
22import graphql from 'graphql'
3- import expressGraphQL from 'express- graphql'
3+ import { createHandler } from 'graphql-http/lib/use/http '
44
55const app = new App ( )
66const port = parseInt ( process . env . PORT ) || 3000
@@ -15,13 +15,8 @@ const rootValue = {
1515 hello : ( ) => 'Hello world!'
1616}
1717
18- app . use (
19- '/graphql' ,
20- expressGraphQL . graphqlHTTP ( {
21- schema,
22- graphiql : { headerEditorEnabled : true } ,
23- rootValue
24- } )
25- )
18+ const handler = createHandler ( { schema, rootValue } )
19+
20+ app . use ( '/graphql' , handler )
2621
2722app . listen ( port , ( ) => console . log ( `Listening on http://localhost:${ port } ` ) )
Original file line number Diff line number Diff line change 44 "private" : true ,
55 "dependencies" : {
66 "@tinyhttp/app" : " workspace:*" ,
7- "express- graphql" : " ^0.12.0 " ,
8- "graphql" : " ^16.6 .0"
7+ "graphql" : " ^16.7.1 " ,
8+ "graphql-http " : " ^1.21 .0"
99 },
1010 "scripts" : {
1111 "start" : " node index.js"
Original file line number Diff line number Diff line change 33 "name" : " tinyhttp-prisma-graphql" ,
44 "type" : " module" ,
55 "scripts" : {
6- "start" : " node index.js"
6+ "start" : " node index.js" ,
7+ "postinstall" : " prisma generate"
78 },
89 "dependencies" : {
9- "@prisma/client" : " 3.5.0 " ,
10+ "@prisma/client" : " 5.1.1 " ,
1011 "@tinyhttp/app" : " workspace:*" ,
1112 "express-graphql" : " ^0.12.0" ,
12- "graphql" : " ^16.0.1"
13+ "graphql" : " ^16.7.1"
14+ },
15+ "devDependencies" : {
16+ "prisma" : " ^5.1.1"
1317 }
1418}
Original file line number Diff line number Diff line change 77 "postinstall" : " prisma generate"
88 },
99 "dependencies" : {
10- "@prisma/client" : " 4.11.0 " ,
10+ "@prisma/client" : " 5.1.1 " ,
1111 "@tinyhttp/app" : " workspace:*" ,
12- "milliparsec" : " ^2.2.2 "
12+ "milliparsec" : " ^2.3.0 "
1313 },
1414 "devDependencies" : {
15- "prisma" : " ^4.11.0 "
15+ "prisma" : " ^5.1.1 "
1616 }
1717}
Original file line number Diff line number Diff line change 44 "type" : " module" ,
55 "dependencies" : {
66 "@tinyhttp/app" : " workspace:*" ,
7- "fastest-validator" : " ^1.16 .0" ,
8- "milliparsec" : " ^2.2.2 "
7+ "fastest-validator" : " ^1.17 .0" ,
8+ "milliparsec" : " ^2.3.0 "
99 },
1010 "scripts" : {
1111 "start" : " node index.js"
Original file line number Diff line number Diff line change 44 "type" : " module" ,
55 "dependencies" : {
66 "@tinyhttp/app" : " workspace:*" ,
7- "sirv" : " ^2.0.2 " ,
8- "vue" : " ^3.2.47 " ,
7+ "sirv" : " ^2.0.3 " ,
8+ "vue" : " ^3.3.4 " ,
99 "vue-server-renderer" : " ^2.7.14"
1010 },
1111 "scripts" : {
Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ node index.js
1717now open a few terminal windows and send messages:
1818
1919``` sh
20- $ wscat -c http ://localhost:3000/chat
21- # > hello
20+ $ wscat -c ws ://localhost:3000/chat
21+ # > hello there
2222# < hello
2323# < someone else sent this
2424# >
Original file line number Diff line number Diff line change 1- import { App } from '@tinyhttp/app'
2- import { tinyws } from 'tinyws'
1+ import { App , } from '@tinyhttp/app'
2+ import { tinyws , } from 'tinyws'
33
44const app = new App ( )
55
66app . use ( tinyws ( ) )
77
8- app . use ( '/hmr' , async ( req , res ) => {
8+ let connections = [ ]
9+
10+ app . use ( '/chat' , async ( req ) => {
911 if ( req . ws ) {
1012 const ws = await req . ws ( )
1113
12- return ws . send ( 'hello there' )
13- } else {
14- res . send ( 'Hello from HTTP!' )
14+ connections . push ( ws )
15+
16+ ws . on ( 'message' , ( message ) => {
17+ console . log ( 'Received message:' , message . toString ( ) )
18+
19+ // broadcast
20+ connections . forEach ( ( socket ) => socket . send ( message ) )
21+ } )
22+
23+ ws . on ( 'close' , ( ) => ( connections = connections . filter ( ( conn ) => ( conn === ws ? false : true ) ) ) )
1524 }
1625} )
1726
18- app . listen ( 3000 )
27+ app . listen ( 3000 )
You can’t perform that action at this time.
0 commit comments