From 8499477ce76c971fe2e1eda065f0d5a61251d6c9 Mon Sep 17 00:00:00 2001 From: jthicks91 Date: Mon, 21 Oct 2019 16:18:02 -0700 Subject: [PATCH 1/3] Still trying to get InputObjectType to work for favoriting beaches mutation --- models/user.js | 10 +++++++++- schema/schema.js | 30 +++++++++++++++++++++++------- schema/userInputType.js | 0 3 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 schema/userInputType.js diff --git a/models/user.js b/models/user.js index 8226a4c..3c3e85c 100644 --- a/models/user.js +++ b/models/user.js @@ -49,7 +49,15 @@ const UserSchema = new Schema({ persona: { type: String, required: false - } + }, + favoriteBeach: [ + { + name: { + type: String, + required: false + } + } + ] }); module.exports = mongoose.model("User", UserSchema); diff --git a/schema/schema.js b/schema/schema.js index 1e88002..815d1ae 100644 --- a/schema/schema.js +++ b/schema/schema.js @@ -174,6 +174,14 @@ const LocationType = new GraphQLObjectType({ // Future UserType for logged in user control +let favoriteType = new GraphQLInputObjectType({ + name: "favoriteType", + fields: () => ({ + cognitoUserId: { type: new GraphQLNonNull(GraphQLString) }, + name: { type: GraphQLString() } + }) +}); + const UserType = new GraphQLObjectType({ name: "User", fields: () => ({ @@ -187,7 +195,8 @@ const UserType = new GraphQLObjectType({ phoneInput: { type: GraphQLString }, regionInput: { type: GraphQLString }, beachInput: { type: GraphQLString }, - persona: { type: GraphQLString } + persona: { type: GraphQLString }, + favoriteBeach: { type: new GraphQLList(favoriteType) } }) }); @@ -208,6 +217,13 @@ const RootQuery = new GraphQLObjectType({ return User.findById(args.id); } }, + favoriteBeach: { + type: new GraphQLList(favoriteType), + args: { id: { type: GraphQLID } }, + resolve(parent, args) { + return favoriteType.findById(args.id); + } + }, filterUser: { type: new GraphQLList(UserType), args: getGraphQLQueryArgs(UserType), @@ -259,7 +275,8 @@ const Mutation = new GraphQLObjectType({ phoneInput: { type: GraphQLString }, regionInput: { type: GraphQLString }, beachInput: { type: GraphQLString }, - persona: { type: GraphQLString } + persona: { type: GraphQLString }, + favoriteBeach: { type: new GraphQLList(favoriteType) } }, async resolve(parent, args) { let user = new User({ @@ -273,7 +290,8 @@ const Mutation = new GraphQLObjectType({ phoneInput: args.phoneInput, regionInput: args.regionInput, beachInput: args.beachInput, - persona: args.persona + persona: args.persona, + favoriteBeach: args.favoriteType }); let mUser = await hb(user); @@ -294,16 +312,14 @@ const Mutation = new GraphQLObjectType({ phoneInput: { type: GraphQLString }, regionInput: { type: GraphQLString }, beachInput: { type: GraphQLString }, - persona: { type: GraphQLString } + persona: { type: GraphQLString }, + favoriteBeach: { type: new GraphQLList(favoriteType) } }, resolve(root, args) { return new Promise((resolve, reject) => { User.findOneAndUpdate( { cognitoUserId: args.cognitoUserId - // regionInput: args.regionInput, - // beachInput: args.beachInput, - // persona: args.persona }, args, { diff --git a/schema/userInputType.js b/schema/userInputType.js new file mode 100644 index 0000000..e69de29 From c55ce615e346119f439c7691427513c2b6013aca Mon Sep 17 00:00:00 2001 From: focused220 Date: Thu, 24 Oct 2019 17:03:45 -0700 Subject: [PATCH 2/3] saving changes --- api/worldWeatherOnline.js | 12 +++++++++--- schema/schema.js | 11 +++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/api/worldWeatherOnline.js b/api/worldWeatherOnline.js index a33458b..63ac9dd 100644 --- a/api/worldWeatherOnline.js +++ b/api/worldWeatherOnline.js @@ -3,15 +3,19 @@ const { GraphQLObjectType, GraphQLString, GraphQLList, + GraphQLInt, } = graphql; // World Weather Online API + + const WwoAPIType = new GraphQLObjectType({ name: "WwoAPI", fields: () => ({ - data: { type: DataType } - }) + request: { type: GraphQLList(RequestType) }, + weather: { type: GraphQLList(HourlyType) } + }), }); const DataType = new GraphQLObjectType({ @@ -66,8 +70,10 @@ const AstronomyType = new GraphQLObjectType({ }); const HourlyType = new GraphQLObjectType({ - name: "hourly", + name: "Hourly", fields: () => ({ + waterTemperature: {type: GraphQLString}, + swellHeight: {type: GraphQLString}, windspeedMiles: { type: GraphQLString }, windspeedKmph: { type: GraphQLString }, winddir16Point: { type: GraphQLString }, diff --git a/schema/schema.js b/schema/schema.js index 7b6746d..35e192a 100644 --- a/schema/schema.js +++ b/schema/schema.js @@ -26,7 +26,7 @@ const { GraphQLList, GraphQLNonNull, GraphQLFloat, - GraphQLInterfaceType + } = graphql; const LocationType = new GraphQLObjectType({ @@ -84,7 +84,7 @@ const LocationType = new GraphQLObjectType({ key: process.env.WWO_API, q: ` ${parent.LATITUDE}, ${parent.LONGITUDE}`, format: "json", - num_of_days: 1, + num_of_days: 10, // change this to more number of days fx: "yes", moonrise: "yes", tp: 24 @@ -224,6 +224,13 @@ const RootQuery = new GraphQLObjectType({ return Location.find({}); } }, + location:{ + type: new GraphQLList(LocationType), + args: {ID: {type: GraphQLID}}, + resolve(parent, args){ + return Location.find({ID: args.ID}).catch(error =>{console.log(error)}) + } + }, users: { type: new GraphQLList(UserType), resolve(parent, args) { From 12520251411735de2256ff1347246b96bc148406 Mon Sep 17 00:00:00 2001 From: focused220 Date: Sat, 26 Oct 2019 14:24:02 -0700 Subject: [PATCH 3/3] completed ratings mutation for beach location --- npm-debug.log | 45 ------------------- schema/schema.js | 110 ++++++++++++----------------------------------- 2 files changed, 28 insertions(+), 127 deletions(-) delete mode 100644 npm-debug.log diff --git a/npm-debug.log b/npm-debug.log deleted file mode 100644 index 3a4c0a8..0000000 --- a/npm-debug.log +++ /dev/null @@ -1,45 +0,0 @@ -0 info it worked if it ends with ok -1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ] -2 info using npm@3.5.2 -3 info using node@v8.10.0 -4 verbose run-script [ 'prestart', 'start', 'poststart' ] -5 info lifecycle location_query@1.0.0~prestart: location_query@1.0.0 -6 silly lifecycle location_query@1.0.0~prestart: no script for prestart, continuing -7 info lifecycle location_query@1.0.0~start: location_query@1.0.0 -8 verbose lifecycle location_query@1.0.0~start: unsafe-perm in lifecycle true -9 verbose lifecycle location_query@1.0.0~start: PATH: /usr/share/npm/bin/node-gyp-bin:/home/focus/Documents/Lambda/Labs/HowsTheWater/backend/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin -10 verbose lifecycle location_query@1.0.0~start: CWD: /home/focus/Documents/Lambda/Labs/HowsTheWater/backend -11 silly lifecycle location_query@1.0.0~start: Args: [ '-c', 'node app.js' ] -12 silly lifecycle location_query@1.0.0~start: Returned: code: 1 signal: null -13 info lifecycle location_query@1.0.0~start: Failed to exec start script -14 verbose stack Error: location_query@1.0.0 start: `node app.js` -14 verbose stack Exit status 1 -14 verbose stack at EventEmitter. (/usr/share/npm/lib/utils/lifecycle.js:232:16) -14 verbose stack at emitTwo (events.js:126:13) -14 verbose stack at EventEmitter.emit (events.js:214:7) -14 verbose stack at ChildProcess. (/usr/share/npm/lib/utils/spawn.js:24:14) -14 verbose stack at emitTwo (events.js:126:13) -14 verbose stack at ChildProcess.emit (events.js:214:7) -14 verbose stack at maybeClose (internal/child_process.js:925:16) -14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) -15 verbose pkgid location_query@1.0.0 -16 verbose cwd /home/focus/Documents/Lambda/Labs/HowsTheWater/backend -17 error Linux 4.15.0-65-generic -18 error argv "/usr/bin/node" "/usr/bin/npm" "start" -19 error node v8.10.0 -20 error npm v3.5.2 -21 error code ELIFECYCLE -22 error location_query@1.0.0 start: `node app.js` -22 error Exit status 1 -23 error Failed at the location_query@1.0.0 start script 'node app.js'. -23 error Make sure you have the latest version of node.js and npm installed. -23 error If you do, this is most likely a problem with the location_query package, -23 error not with npm itself. -23 error Tell the author that this fails on your system: -23 error node app.js -23 error You can get information on how to open an issue for this project with: -23 error npm bugs location_query -23 error Or if that isn't available, you can get their info via: -23 error npm owner ls location_query -23 error There is likely additional logging output above. -24 verbose exit [ 1, true ] diff --git a/schema/schema.js b/schema/schema.js index 741bec8..300e35f 100644 --- a/schema/schema.js +++ b/schema/schema.js @@ -26,12 +26,11 @@ const { GraphQLList, GraphQLNonNull, GraphQLFloat, - GraphQLInputObjectType, - GraphQLInterfaceType + GraphQLInputObjectType } = graphql; const ratingsType = new GraphQLObjectType({ - name: "Object", + name: "Ratings", fields: () => ({ _id: { type: GraphQLID }, user: { type: GraphQLInt }, @@ -264,21 +263,20 @@ const RootQuery = new GraphQLObjectType({ } }); -// const ratingsTypeMut = new GraphQLInputObjectType({ -// name: "beachRatings", -// fields: () => ({ -// _id: { type: GraphQLID }, -// user: { type: GraphQLInt }, -// rating: { type: GraphQLInt } -// }) -// }); +const ratingsTypeMut = new GraphQLInputObjectType({ + name: "beachRatings", + fields: () => ({ + user: { type: GraphQLInt }, + rating: { type: GraphQLInt } + }) +}); -// const favbeachTypeMut = new GraphQLInputObjectType({ -// name: "beachRatings", -// fields: () => ({ -// name: { type: GraphQLID } -// }) -// }); +const favbeachTypeMut = new GraphQLInputObjectType({ + name: "beachRatings", + fields: () => ({ + name: { type: GraphQLID } + }) +}); const Mutation = new GraphQLObjectType({ name: "Mutation", @@ -357,72 +355,20 @@ const Mutation = new GraphQLObjectType({ }); }); } + }, + updateRatings: { + type: LocationType, + args: { + ID: { type: GraphQLID }, + input: { type: ratingsTypeMut } + }, + async resolve(root, args) { + + const ratingUpdate = await Location.findOneAndUpdate({ID:args.ID}, {$push:{Ratings: args.input}}, {new:true} ); + return(ratingUpdate); + + } } - // updateBeach: { - // type: LocationType, - // args: { - // ID: { type: GraphQLID }, - // DISTRICT: { type: GraphQLString }, - // CountyNum: { type: GraphQLInt }, - // COUNTY: { type: GraphQLString }, - // NameMobileWeb: { type: GraphQLString }, - // LocationMobileWeb: { type: GraphQLString }, - // DescriptionMobileWeb: { type: GraphQLString }, - // PHONE_NMBR: { type: GraphQLString }, - // PARKING: { type: GraphQLString }, - // DSABLDACSS: { type: GraphQLString }, - // RESTROOMS: { type: GraphQLString }, - // VISTOR_CTR: { type: GraphQLString }, - // DOG_FRIENDLY: { type: GraphQLString }, - // EZ4STROLLERS: { type: GraphQLString }, - // PCNC_AREA: { type: GraphQLString }, - // CAMPGROUND: { type: GraphQLString }, - // SNDY_BEACH: { type: GraphQLString }, - // DUNES: { type: GraphQLString }, - // RKY_SHORE: { type: GraphQLString }, - // BLUFF: { type: GraphQLString }, - // STRS_BEACH: { type: GraphQLString }, - // PTH_BEACH: { type: GraphQLString }, - // BLFTP_TRLS: { type: GraphQLString }, - // BLFTP_PRK: { type: GraphQLString }, - // WLDLFE_VWG: { type: GraphQLString }, - // TIDEPOOL: { type: GraphQLString }, - // VOLLEYBALL: { type: GraphQLString }, - // FISHING: { type: GraphQLString }, - // BOATING: { type: GraphQLString }, - // LIST_ORDER: { type: GraphQLString }, - // GEOGR_AREA: { type: GraphQLString }, - // LATITUDE: { type: GraphQLFloat }, - // LONGITUDE: { type: GraphQLFloat }, - // REGION: { type: GraphQLString }, - // Photo_1: { type: GraphQLString }, - // Photo_2: { type: GraphQLString }, - // Photo_3: { type: GraphQLString }, - // Photo_4: { type: GraphQLString }, - // Bch_whlchr: { type: GraphQLString }, - // BIKE_PATH: { type: GraphQLString }, - // BT_FACIL_TYPE: { type: GraphQLString } - // // Ratings: { type: ratingsTypeMut } - // }, - // resolve(root, args) { - // return new Promise((resolve, reject) => { - // User.findOneAndUpdate( - // { - // NameMobileWeb: args.NameMobileWeb - // }, - // args, - // { - // new: true, - // useFindAndModify: false - // } - // ).exec((err, res) => { - // console.log(res); - // if (err) reject(err); - // else resolve(res); - // }); - // }); - // } - // } } });