How to use the api.query function in api

To help you get started, we’ve selected a few api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github deptofdefense / anet / client / src / pages / App.js View on Github external
fetchData() {
		API.query(/* GraphQL */`
			person(f:me) {
				id, name, role, emailAddress, rank, status
				position {
					id, name, type, isApprover
					organization { id, shortName , allDescendantOrgs { id }}
				}
			}

			adminSettings(f:getAll) {
				key, value
			}

			organizationList(f:getTopLevelOrgs, type: ADVISOR_ORG) {
				list { id, shortName }
			}
		`).then(data => {
github deptofdefense / anet / client / src / pages / Home.js View on Github external
let queries = this.getQueriesForUser(currentUser)
		//Run those four queries
		let graphQL = /* GraphQL */`
			tileOne: reportList(f:search, query:$queryOne) { totalCount},
			tileTwo: reportList(f:search, query: $queryTwo) { totalCount},
			tileThree: reportList(f:search, query: $queryThree) { totalCount },
			tileFour: reportList(f:search, query: $queryFour) { totalCount },
			savedSearches: savedSearchs(f:mine) {id, name, objectType, query}`
		let variables = {
			queryOne: queries[0].query,
			queryTwo: queries[1].query,
			queryThree: queries[2].query,
			queryFour: queries[3].query
		}

		API.query(graphQL, variables,
			"($queryOne: ReportSearchQuery, $queryTwo: ReportSearchQuery, $queryThree: ReportSearchQuery, $queryFour: ReportSearchQuery)")
		.then(data => {
			let selectedSearch = data.savedSearches && data.savedSearches.length > 0 ? data.savedSearches[0] : null
			this.setState({
				tileCounts: [data.tileOne.totalCount, data.tileTwo.totalCount, data.tileThree.totalCount, data.tileFour.totalCount],
				savedSearches: data.savedSearches,
				selectedSearch: selectedSearch
			})
		})
	}
github deptofdefense / anet / client / src / pages / organizations / Edit.js View on Github external
fetchData(props) {
		API.query(/* GraphQL */`
			organization(id:${props.params.id}) {
				id, shortName, longName, type,
				parentOrg { id, shortName, longName }
				approvalSteps { id, name
					approvers { id, name, person { id, name}}
				},
				poams { id, shortName, longName}
			}
		`).then(data => {
			this.setState({
				organization: new Organization(data.organization),
				originalOrganization: new Organization(data.organization)
			})
		})
	}
github deptofdefense / anet / client / src / pages / organizations / New.js View on Github external
fetchData(props) {
		if (props.location.query.parentOrgId) {
			API.query(/* GraphQL */`
				organization(id: ${props.location.query.parentOrgId}) {
					id, shortName, longName, type
				}
			`).then(data => {
				let {organization, originalOrganization} = this.state
				organization.parentOrg = new Organization(data.organization)
				organization.type = organization.parentOrg.type

				originalOrganization.parentOrg = new Organization(data.organization)
				originalOrganization.type = originalOrganization.parentOrg.type

				this.setState({organization, originalOrganization})
			})
		}
	}
github deptofdefense / anet / client / src / pages / admin / Index.js View on Github external
fetchData(props) {
		API.query(/* GraphQL */`
			adminSettings(f:getAll) { key, value }
		`).then(data => {
			let settings = {}
			data.adminSettings.forEach(setting => settings[setting.key] = setting.value)
			this.setState({settings})
		})
	}
github deptofdefense / anet / client / src / pages / poams / Edit.js View on Github external
fetchData(props) {
		API.query(/* GraphQL */`
			poam(id:${props.params.id}) {
				id, shortName, longName, status,
				responsibleOrg {id,shortName, longName}
			}
		`).then(data => {
			this.setState({poam: new Poam(data.poam), originalPoam: new Poam(data.poam)})
		})
	}
github deptofdefense / anet / client / src / pages / reports / Show.js View on Github external
fetchData(props) {
		API.query(/* GraphQL */`
			report(id:${props.params.id}) {
				id, intent, engagementDate, atmosphere, atmosphereDetails
				keyOutcomes, reportText, nextSteps, cancelledReason

				state

				location { id, name }
				author {
					id, name, rank,
					position {
						organization {
							shortName, longName
							approvalSteps {
								id, name,
								approvers {
									id, name,
github deptofdefense / anet / client / src / pages / people / Edit.js View on Github external
fetchData(props) {
		API.query(/*GraphQL*/ `
			person(id:${props.params.id}) {
				id,
				name, rank, role, emailAddress, phoneNumber, status
				biography, country, gender, endOfTourDate,
				position {
					id, name
				}
			}
		`).then(data => {
			if (data.person.endOfTourDate) {
				data.person.endOfTourDate = moment(data.person.endOfTourDate).format()
			}
			this.setState({person: new Person(data.person), originalPerson: new Person(data.person)})
		})
	}
github deptofdefense / anet / client / src / graphqlapi.js View on Github external
run(parts) {
		let query = parts.map(p => p.queryString).join(',\n')
		let variables = {}
		let variableDefs = []
		parts.forEach(part => {
			part.variables.forEach(variable => {
				variables[variable.name] = variable.value
				variableDefs.push(`$${variable.name}: ${variable.type}`)
			})
		})

		let variableDef = '(' + variableDefs.join(', ') + ')'

		return API.query(query, variables, variableDef)
	},