hey folks let's take a look at how we can deploy
a sub query project to the subquery hosted solution namely called subquery project
first of all let's go to the project link on the subquery home page and i'm going to show you
what we are trying to achieve you can see i've got a project here already so let's open this
then i'll jump into the explorer
and in the playground here i'm going to hit the run and you'll see data being returned so this
is what we are trying to do we're trying to get a project into this hosted solution platform and
run our query so the first thing we want to do is take our project and make sure it's in
our github repository because the project is going to pull the code from this repository so there are
two ways you can do this you can go ahead and create or upload your own project to your repo
or what i'm going to do is jump into the sub query github repository and i'll pick a repository to
copy i'm going to pick one with the prefix of tutorial and you can pick any one of these if you
want i'm going to choose the account transfer one so let's go ahead and copy this by clicking on the
fork and i'm just going to ask me where do i want to fork this to let's go my repository
and there we have it so now let's jump into sub query project and note that i have already logged
in so if i haven't logged in already you'll notice that it will ask me to log in with my github
credentials and if you're doing this for the first time it will need authorization doing what's
called the olworth dance so i've already done this so it's going to log me straight in and just a
quick note that at the top here if you are using your organizational github repository instead of
your personal one you can select it in here as well and if i go back to the documentation here
just referring back to publishing a project you can see here on the right hand side adding
a github organization account because it's actually very common to publish your project
under the name of your github organization rather than a personal account so it's in
this drop down where you can change it and of course you do need to connect it first of all
so i've logged in as my personal account which is fine and then the next thing i
do is click create project now i get a few fields that i need to fill out
of course let's go from the top to bottom the project name i'll call it say account transfer
the subtitle let me go into the repo here let's call it a one-to-many example copy this
i'll spell that correctly and then in my description i'll go ahead and maybe
maybe copy this whole sentence here out now note if i copy this above here
i'm going to exceed the 100 character limit just something of interest there
and let me fix this spelling here and then i'll select the github repo and i'll also
click here to upload a logo just to make it nice and tidy and note that the description and the
name and subtitle these are used for marketing purposes and seo as well so it's ideal to have
this as descriptive and as accurate as possible now as mentioned in previous videos as well if i
select this here it hides it from the public sub query explorer meaning that an
explorer here i won't actually see the project but in my case i'm happy to make this public
so i'll leave it unticked and then i'll hit create project now once i do this you'll see
that i've got the title the subtitle here the description all displayed the github repository
but the note here says i have to deploy my project first before sub query is able to index my data
i've got what's called a production slot and a staging slot you can think of your staging slot
as like a development environment for you to do some testing however and this is important to note
you want to do all your unit testing on your local host first so on your laptop once it's passed and
you're happy you can deploy it to a staging slot and then use this for say integration or systems
testing before promoting it to production you don't really want to do your unit testing
in a staging slot so what i'm going to do here is click on deploy and then i get a whole bunch
of options available to me i can go ahead and commit the latest version which is this one here
or you can see i've got older versions as well so i've got a choice i'll go ahead and make this the
latest version i can then go ahead and override various endpoints so this project is using the
default polkadot mainnet endpoint and we can check this by going into the github repository
here and looking at our project yaml file and you can see it's consuming the polka dot api here
but what i'm going to do is show you how i can overwrite this with say a kusama endpoint
i can also override the dictionary endpoint here so this code here is using a dictionary
and if you're not sure what this is i'll demonstrate this when i deploy the project
because it allows you to make your indexing a lot quicker by only grabbing the data that you need
there's actually more information on a dictionary in the documentation if i can find it
where on the left hand side here you can see how does a sub query dictionary work and
it goes into the inner workings so highly recommend reading this as well i'll leave
the dictionary blank allowing the project to use the default and then down below here i've got some
previous versions of the indexer that i can choose from as well as the query engine for both of these
i'll leave it as the latest version and quite often this is the recommendation as well unless
of course you're writing some code for a specific older version so let's go ahead and deploy this
and this will take a minute or two because in the back end
the hardware the environment is being provisioned automatically
the cpus the virtual machine is all being created so sit back relax and catch you in a few
okay so you can see now that the staging slot is up and running so the options we have here
are we can promote to production deploy a new version view this on sub query explorer
or we can also delete the project as well so let's go ahead and view this on sub query explorer
and you can see that it's starting to synchronize the blocks so from 180 to 210
and we've got quite a way to go down below you can see the network that it's connected
to so it's kusama because we overrode the default which was polka dot we've got a link to the github
repository a commit version so we can identify the exact version of this code and of course a
query api endpoint that i'll show you how to use in a minute down below we've got the playground
this query here is from my cache so if i run this it probably won't work it returns an empty data
set but if i go to the actual repository here go into the home page scrolling down you'll see
i've got an example query to run so i'm going to copy this and let's go and paste it in here
and let's run this and what happens is we don't get any data returning
because at the moment we're just on 450 blocks or 480 now and this is trying to synchronize from the
beginning of time so it's going to take quite a while before we get any real data and there's
actually a way to get around this because i'm actually not using the dictionary at the moment
because i'm pointing to the kusama endpoint with the dictionary pointing to production
so if i show you here i'm pointing to this particular dictionary here and if i look at the
dictionary code which we'll do let's go back into project explorer and i do a search for dictionary
you'll see the polkadot dictionary here so my endpoint is pointing to
this one instead of the kusama dictionary which is where i should be pointing to so
what happens is if i go back to my project dashboard
and jump back into this i can actually deploy another version where i'm not overriding the
kusama endpoint to show you what happens and there's actually a bit of a trick here where
i can actually promote this project into production like so and when i do this what
actually happens under the covers is the staging slot actually becomes production so it's not like
i'm now going to rebuild a new environment and call it production and then migrate the code
this staging slot actually becomes production so just the name changes so you'll see this
when i go promote to production this says that the staging slot to production will
seamlessly redirect traffic to minimize any downtime the previous production slot will
be replaced and deleted so let's go promote and there you go there is no downtime because
of how it works and then i've got a free staging slot up here now if i go ahead and deploy this
and i don't overwrite any of the endpoints let's go deploy update
we can do a quick comparison obviously after this has fully deployed
so just sit tight and again we'll be back shortly
right so now we've got the staging slot up and running let's jump in and we'll do a
quick comparison first of all we'll go to the production slot and we'll view this one here
and i'll run the query again and we've got no data being returned and in fact the syncing
at the moment has stopped let me go back and check out the staging slot with the dictionary
and you can see that all of a sudden we've got two entities already
up to 29 000 blocks and if i run my code
i've got data coming back already so this is the main advantage of using a dictionary
because what it does is it doesn't go into every single block
it only grabs the block that has the data that it needs and because of this it is much much faster
okay so that is how you can deploy a project into subquery projects or the hosted solution
now what i want to do here is show you how you can use this query endpoint to perform a query
over say http curl i've got my terminal screen here let me increase this and i can run curl
and copy out this endpoint and paste it here and then what i want to do next is use the
d flag for data and then i want to copy out this particular request
and paste it in here let's go query equals
hit enter and of course you could format this nicely if you wanted to but
you can see here that the data we've got some data coming back
and it actually equals what we see on screen let me run this again
there we go and if i do a comparison i've got 19 76 81 19 76 81 so this first
item here and of course if i go down below i've got 72 100 which is 72 100 here so using the curl
command you could include this in your say your web application and make a query to get the data
to display in your mobile app for instance so there we have it a video on how you can take a
project upload it into sub query projects run it inside playground and also promote
the project to production as well one thing to note which i'll just quickly show you
it's actually quite important to ensure you keep this nice and tidy so
very useful to delete the project here by deleting the staging slot however do note that you can't go
into your production slot and delete this if you want to delete this then the way to do this is to
go up top here and select delete project deleting the entire project itself so if i go yes to this
the project will be deleted and it's gone from my dashboard page great hope that was useful
and i'll catch you on the next video
you