Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to use GraphQL `input` for adding Flight Controllers #1

Merged
merged 2 commits into from Jun 27, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -45,19 +45,25 @@ function post(parent, args, context, info) {

function addFlightController(parent, args, context, info){
const userId = getUserId(context)
console.log("Adding Flight Controller as", userId, args)

return context.prisma.createFlightController({
postedBy: { connect: { id: userId } },
...args
})
}

function addFlightControllerEasy(parent, args, context, info){
const userId = getUserId(context)

return context.prisma.createFlightController({
postedBy: { connect: { id: userId } },
...args.flightController
})
}

async function updateLink(parent, args, context, info) {
const userId = getUserId(context)
console.log('updateLink', args)
const existingLink = await context.prisma.link({ id: args.id })
console.log('existingLink', existingLink)
if (!existingLink) {
throw new Error('No such link found by that ID')
}
@@ -94,6 +100,7 @@ module.exports = {
updateLink,
vote,
addFlightController,
addFlightControllerEasy
}

// Mutation: {
@@ -13,6 +13,9 @@ type Mutation {
url: String!,
description: String!
): Link!
addFlightControllerEasy(
flightController: FlightControllerInput!
) : FlightController
addFlightController(
name: String,
releaseDate: String,
@@ -80,6 +83,36 @@ type Link {
votes: [Vote!]!
}

input FlightControllerInput{
id: ID
name: String
releaseDate: String
uarts: Int
GyroOne: Float
GyroTwo: Float
weightInGrams: Float
cpu: String
dimensions: String
description: String
holePattern: String
voltageInputMin: Float
voltageInputMax: Float
osd: Boolean
accelerometer: Boolean
barometer: Boolean
spektrumPort: Boolean
usbInterface: Boolean
LedWS2812Support: Boolean
RSSIPad: Boolean
currentSensor: Boolean
beeperPad: Boolean
beeperOnBoard: Boolean
antiVibrationGrommets: Boolean
builtInReceiver: String
postedBy: UserInput
createdAt: DateTime
}

type FlightController {
id: ID
name: String
@@ -123,6 +156,12 @@ type User {
flightControllers: [FlightController!]!
}

input UserInput {
id: ID!
name: String!
email: String!
}

enum ReceiverProtocol{
CROSSFIRE
DSMX
@@ -37,32 +37,8 @@ import { FC_LIST_QUERY } from './FlightControllers/FlightControllerList.jsx'
// }

const FC_MUTATION = gql`
mutation FcMutation(
$name: String,
$releaseDateUpdated: String,
$description: String,
$uarts: Int,
$weightInGrams: Float,
$cpu: String,
$dimensions: String,
$holePattern: String,
$voltageInputMin: Float,
$voltageInputMax: Float,
$osd: Boolean,
){
addFlightController(
name: $name,
uarts: $uarts,
description: $description,
releaseDate: $releaseDateUpdated,
weightInGrams: $weightInGrams,
cpu: $cpu,
dimensions: $dimensions,
holePattern: $holePattern,
voltageInputMin: $voltageInputMin
voltageInputMax: $voltageInputMax
osd: $osd
){
mutation FcMutation($flightController: FlightControllerInput!){
addFlightControllerEasy(flightController: $flightController){
id
createdAt
description
@@ -131,6 +107,10 @@ class AddFlightController extends Component {
cpu, weightInGrams,
} = this.state

let flightController = {...this.state}
flightController.releaseDate = this.state.releaseDateUpdated;
delete flightController.releaseDateUpdated;

return (
<Container fluid>
<h1>Testing</h1>
@@ -229,9 +209,7 @@ class AddFlightController extends Component {
<Mutation
mutation={FC_MUTATION}
variables={{
name, uarts, description, releaseDateUpdated,
voltageInputMax, voltageInputMin, cpu, weightInGrams,holePattern, dimensions,
osd,
flightController
}}
onCompleted={() => this.props.history.push('/products/flight-controller/1')}
update={(store, { data: { flightController } }) => {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.