Skip to content

Commit

Permalink
Merge pull request #5 from fac20/queries
Browse files Browse the repository at this point in the history
Queries
  • Loading branch information
fairyaksh authored Oct 22, 2020
2 parents 42c9a6f + 68f4b9f commit 6a055e4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 49 deletions.
34 changes: 6 additions & 28 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,13 @@ import Onboarding from "./components/Onboarding/Onboarding.jsx";
// import Requests from "./components/Requests/Requests";
// import Signup from "./components/SignupLogin/Signup";
// import Login from "./components/SignupLogin/Login";
// import query from "./utils/SearchQueries";
export default function App() {
// React.useEffect(() => {
// const user_input = "Jane";
// const userSearchQuery = `
// {
// users(where: {full_name: {_ilike: "%e%"}}) {
// bio
// email
// }
// }`;
// const url = "https://tfb-mlink.herokuapp.com/v1/graphql";
// const options = {
// method: "POST",
// headers: {
// "Content-type": "application/json",
// "x-hasura-admin-secret": "secretKey"
// },
// body: JSON.stringify({ userSearchQuery })
// };
import query from "./utils/SearchQueries";

// fetch(url, options)
// .then((response) => {
// if (!response.ok) throw new Error("Request failed");
// return response.json();
// })
// .then((res) => console.log(res))
// .catch(console.error);
// }, []);
export default function App() {
React.useEffect(() => {
const input = "%Doe%";
query(input);
}, []);

return (
<Router>
Expand Down
43 changes: 22 additions & 21 deletions src/utils/SearchQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,34 @@
// specialty
// medical school

const userSearchQuery = `
query SearchByName($user_input: String!){
{
users {
full_name(
where: { full_name: {_ilike: "%$user_input%"}})
}
}
}`;
// Imported as query to App.js
export default (input) => {
input = `%${input}%`;
const variables = { input: input };
const query = `
query SearchByName($input: String!) {
users(where: {full_name: {_ilike: $input}}) {
bio
email
}
}`;

export default (user_input) => {
const url = "https://tfb-mlink.herokuapp.com/v1/graphql";
const options = {
fetch("https://tfb-mlink.herokuapp.com/v1/graphql", {
method: "POST",
headers: {
"Content-type": "application/json",
"x-hasura-admin-secret": "secretKey",
variables: { user_input }
"content-type": "application/json",
"x-hasura-admin-secret": "secretKey"
},
body: JSON.stringify({ userSearchQuery, user_input })
};

fetch(url, options)
body: JSON.stringify({ query, variables })
})
.then((response) => {
if (!response.ok) throw new Error("Request failed");
return response.json();
})
.then(console.log)
.catch(console.error);
.then((json) => {
console.log(json);
})
.catch((error) => {
console.error(error);
});
};

0 comments on commit 6a055e4

Please sign in to comment.